`generics_defaults.py` mandates that type checkers should allow a class that raises `TypeError` at runtime
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- documentation, testing
Hướng nghiên cứu
Bắt đầu với conformance/tests/generics_defaults.py ở các dòng 191-200 và đối chiếu yêu cầu của nó với đặc tả typing. Sau đó kiểm tra typing.py tại _collect_type_parameters và tái hiện các ví dụ trên những phiên bản cú pháp Python được trích dẫn. Hoàn thành nghĩa là xác định runtime hay đặc tả và bài kiểm tra conformance không nhất quán, kèm theo độ bao phủ hồi quy cho bản sửa được chọn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
This test mandates that type checkers should allow classes that have ParamSpecs-with-defaults following TypeVarTuples: https://github.com/python/typing/blob/22d9392a5ead302cc02c47ecbbcf3aa40106fd9f/conformance/tests/generics_defaults.py#L191-L200
But these fail at runtime. Using Python 3.11 syntax:
% uvx python3.14
Python 3.14.0 (main, Oct 10 2025, 12:54:13) [Clang 20.1.4 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import *
>>> Ts = TypeVarTuple("Ts")
>>> P = ParamSpec("P", default=[int, str])
>>> class A(Generic[*Ts, P]): ...
...
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
class A(Generic[*Ts, P]): ...
~~~~~~~^^^^^^^^
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 402, in inner
return func(*args, **kwds)
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 1157, in _generic_class_getitem
return _GenericAlias(cls, args)
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 1334, in __init__
self.__parameters__ = _collect_type_parameters(
~~~~~~~~~~~~~~~~~~~~~~~~^
args,
^^^^^
enforce_default_ordering=enforce_default_ordering,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 291, in _collect_type_parameters
raise TypeError('Type parameter with a default'
' follows TypeVarTuple')
TypeError: Type parameter with a default follows TypeVarTuple
Using Python <=3.10 syntax:
>>> class B(Generic[Unpack[Ts], P]): ...
...
Traceback (most recent call last):
File "<python-input-4>", line 1, in <module>
class B(Generic[Unpack[Ts], P]): ...
~~~~~~~^^^^^^^^^^^^^^^
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 402, in inner
return func(*args, **kwds)
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 1157, in _generic_class_getitem
return _GenericAlias(cls, args)
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 1334, in __init__
self.__parameters__ = _collect_type_parameters(
~~~~~~~~~~~~~~~~~~~~~~~~^
args,
^^^^^
enforce_default_ordering=enforce_default_ordering,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 291, in _collect_type_parameters
raise TypeError('Type parameter with a default'
' follows TypeVarTuple')
TypeError: Type parameter with a default follows TypeVarTuple
And using Python 3.13+ syntax:
>>> class C[*Ts, **P = [int, str]]: ...
...
Traceback (most recent call last):
File "<python-input-5>", line 1, in <module>
class C[*Ts, **P = [int, str]]: ...
File "<python-input-5>", line 1, in <generic parameters of C>
class C[*Ts, **P = [int, str]]: ...
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 1334, in __init__
self.__parameters__ = _collect_type_parameters(
~~~~~~~~~~~~~~~~~~~~~~~~^
args,
^^^^^
enforce_default_ordering=enforce_default_ordering,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 291, in _collect_type_parameters
raise TypeError('Type parameter with a default'
' follows TypeVarTuple')
TypeError: Type parameter with a default follows TypeVarTuple
Since it seems that the tests are quoting the spec here, is this a bug in the runtime implementation of the typing module? Or should we update the spec and the conformance suite to allow type checkers to catch this runtime error?
- Ngôn ngữ chính
- Python
- Star
- 1.8k
- Fork
- 302
- Merge trung bình
- 23 giờ
- Pull request đã merge (30 ngày)
- 8
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/typing
-
topic: typing spec
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
topic: typing spec
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
topic: documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
topic: documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
topic: conformance tests topic: typing spec
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
Tất cả issue của python/typing
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
zostera/django-bootstrap4#894 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
use-agent-os/agent-os#3276 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·