Skip to content

Commit 96bbf7c

Browse files
committed
don't state that type[Callable] is invalid
1 parent 7f8f6bb commit 96bbf7c

File tree

7 files changed

+23
-7
lines changed

7 files changed

+23
-7
lines changed

conformance/results/mypy/specialtypes_type.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ specialtypes_type.py:143: error: "<typing special form>" has no attribute "unkno
1717
specialtypes_type.py:144: error: "<typing special form>" has no attribute "unknown" [attr-defined]
1818
specialtypes_type.py:145: error: "type[type]" has no attribute "unknown" [attr-defined]
1919
specialtypes_type.py:146: error: "<typing special form>" has no attribute "unknown" [attr-defined]
20+
specialtypes_type.py:179: error: Variable "typing.TypedDict" is not valid as a type [valid-type]
21+
specialtypes_type.py:179: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
22+
specialtypes_type.py:180: error: type[...] can't contain "Literal[...]" [valid-type]
2023
"""
2124
conformance_automated = "Fail"
2225
errors_diff = """

conformance/results/pyrefly/specialtypes_type.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
conformant = "Pass"
2-
conformance_automated = "Pass"
2+
conformance_automated = "Fail"
33
errors_diff = """
4+
Line 180: Expected 1 errors
45
"""
56
output = """
67
ERROR specialtypes_type.py:56:7-15: Argument `type[TeamUser]` is not assignable to parameter `user_class` with type `type[BasicUser | ProUser]` in function `func4` [bad-argument-type]
@@ -12,4 +13,5 @@ ERROR specialtypes_type.py:143:1-12: Class `type` has no class attribute `unknow
1213
ERROR specialtypes_type.py:144:1-12: Class `type` has no class attribute `unknown` [missing-attribute]
1314
ERROR specialtypes_type.py:145:1-12: Class `type` has no class attribute `unknown` [missing-attribute]
1415
ERROR specialtypes_type.py:146:1-12: Class `type` has no class attribute `unknown` [missing-attribute]
16+
ERROR specialtypes_type.py:179:9-18: `TypedDict` is not allowed in this context [invalid-annotation]
1517
"""

conformance/results/pyright/specialtypes_type.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
conformant = "Pass"
1+
conformant = "Fail"
22
output = """
33
specialtypes_type.py:56:7 - error: Argument of type "type[TeamUser]" cannot be assigned to parameter "user_class" of type "type[BasicUser] | type[ProUser]" in function "func4"
44
  Type "type[TeamUser]" is not assignable to type "type[BasicUser] | type[ProUser]"
@@ -20,7 +20,11 @@ specialtypes_type.py:145:5 - error: Cannot access attribute "unknown" for class
2020
  Attribute "unknown" is unknown (reportAttributeAccessIssue)
2121
specialtypes_type.py:146:5 - error: Cannot access attribute "unknown" for class "TA4"
2222
  Attribute "unknown" is unknown (reportAttributeAccessIssue)
23+
specialtypes_type.py:178:9 - error: Type argument for "type" must be a class; callables are not supported (reportInvalidTypeForm)
24+
specialtypes_type.py:179:9 - error: "TypedDict" cannot be used in this context (reportInvalidTypeForm)
2325
"""
24-
conformance_automated = "Pass"
26+
conformance_automated = "Fail"
2527
errors_diff = """
28+
Line 180: Expected 1 errors
29+
Line 178: Unexpected errors ['specialtypes_type.py:178:9 - error: Type argument for "type" must be a class; callables are not supported (reportInvalidTypeForm)']
2630
"""

conformance/results/results.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ <h3>Python Type System Conformance Test Results</h3>
243243
</tr>
244244
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;specialtypes_type</th>
245245
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not treat `type` same as `type[Any]` for assert_type.</p><p>Does not allow access to unknown attributes from object of type `type[Any]`.</p></span></div></th>
246-
<th class="column col2 conformant">Pass</th>
246+
<th class="column col2 not-conformant">Fail</th>
247247
<th class="column col2 conformant">Pass</th>
248248
<th class="column col2 conformant">Pass</th>
249249
</tr>

conformance/results/zuban/specialtypes_type.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ specialtypes_type.py:143: error: "_SpecialForm" has no attribute "unknown" [att
1111
specialtypes_type.py:144: error: "_SpecialForm" has no attribute "unknown" [attr-defined]
1212
specialtypes_type.py:145: error: "_SpecialForm" has no attribute "unknown" [attr-defined]
1313
specialtypes_type.py:146: error: "_SpecialForm" has no attribute "unknown" [attr-defined]
14+
specialtypes_type.py:179: error: Invalid type [valid-type]
15+
specialtypes_type.py:180: error: type[...] can't contain "Literal[...]" [misc]
1416
"""

conformance/tests/specialtypes_type.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Specification: https://typing.readthedocs.io/en/latest/spec/special-types.html#type
66

77

8-
from typing import Any, Callable, Generic, Type, TypeAlias, TypeVar, assert_type
8+
from typing import Any, Callable, Generic, Type, TypeAlias, TypeVar, assert_type, Literal, TypedDict
99

1010

1111
class User:
@@ -173,3 +173,8 @@ def func13(v: type):
173173
class ClassA(Generic[T]):
174174
def method1(self, v: type) -> type[T]:
175175
return v # OK
176+
177+
# > Some other special forms like Literal and TypedDict are not allowed as an argument to type.
178+
c: type[Callable] # OK
179+
t: type[TypedDict] # E
180+
l: type[Literal[1]] # E

docs/spec/special-types.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ concrete class object, e.g. in the above example::
188188
``type[T]`` where ``T`` is a type variable is allowed when annotating the
189189
first argument of a class method (see the relevant section).
190190

191-
Any other :term:`special forms <special form>` like ``Callable`` are not
192-
allowed as an argument to ``type``.
191+
Some other :term:`special forms <special form>` like ``Literal`` and
192+
`TypedDict` are not allowed as an argument to ``type``.
193193

194194
There are some concerns with this feature: for example when
195195
``new_user()`` calls ``user_class()`` this implies that all subclasses

0 commit comments

Comments
 (0)