Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conformance/results/mypy/generics_paramspec_basic.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
conformant = "Pass"
conformant = "Partial"
output = """
generics_paramspec_basic.py:10: error: String argument 1 "NotIt" to ParamSpec(...) does not match variable name "WrongName" [misc]
generics_paramspec_basic.py:15: error: Invalid location for ParamSpec "P" [valid-type]
Expand Down
3 changes: 3 additions & 0 deletions conformance/results/mypy/specialtypes_type.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ specialtypes_type.py:143: error: "<typing special form>" has no attribute "unkno
specialtypes_type.py:144: error: "<typing special form>" has no attribute "unknown" [attr-defined]
specialtypes_type.py:145: error: "type[type]" has no attribute "unknown" [attr-defined]
specialtypes_type.py:146: error: "<typing special form>" has no attribute "unknown" [attr-defined]
specialtypes_type.py:179: error: Variable "typing.TypedDict" is not valid as a type [valid-type]
specialtypes_type.py:179: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
specialtypes_type.py:180: error: type[...] can't contain "Literal[...]" [valid-type]
"""
conformance_automated = "Fail"
errors_diff = """
Expand Down
6 changes: 4 additions & 2 deletions conformance/results/pyrefly/specialtypes_type.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
conformant = "Pass"
conformance_automated = "Pass"
conformant = "Partial"
conformance_automated = "Fail"
errors_diff = """
Line 180: Expected 1 errors
"""
output = """
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]
Expand All @@ -12,4 +13,5 @@ ERROR specialtypes_type.py:143:1-12: Class `type` has no class attribute `unknow
ERROR specialtypes_type.py:144:1-12: Class `type` has no class attribute `unknown` [missing-attribute]
ERROR specialtypes_type.py:145:1-12: Class `type` has no class attribute `unknown` [missing-attribute]
ERROR specialtypes_type.py:146:1-12: Class `type` has no class attribute `unknown` [missing-attribute]
ERROR specialtypes_type.py:179:9-18: `TypedDict` is not allowed in this context [invalid-annotation]
"""
8 changes: 6 additions & 2 deletions conformance/results/pyright/specialtypes_type.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
conformant = "Pass"
conformant = "Fail"
output = """
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"
  Type "type[TeamUser]" is not assignable to type "type[BasicUser] | type[ProUser]"
Expand All @@ -20,7 +20,11 @@ specialtypes_type.py:145:5 - error: Cannot access attribute "unknown" for class
  Attribute "unknown" is unknown (reportAttributeAccessIssue)
specialtypes_type.py:146:5 - error: Cannot access attribute "unknown" for class "TA4"
  Attribute "unknown" is unknown (reportAttributeAccessIssue)
specialtypes_type.py:178:9 - error: Type argument for "type" must be a class; callables are not supported (reportInvalidTypeForm)
specialtypes_type.py:179:9 - error: "TypedDict" cannot be used in this context (reportInvalidTypeForm)
"""
conformance_automated = "Pass"
conformance_automated = "Fail"
errors_diff = """
Line 180: Expected 1 errors
Line 178: Unexpected errors ['specialtypes_type.py:178:9 - error: Type argument for "type" must be a class; callables are not supported (reportInvalidTypeForm)']
"""
6 changes: 3 additions & 3 deletions conformance/results/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ <h3>Python Type System Conformance Test Results</h3>
</tr>
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;specialtypes_type</th>
<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>
<th class="column col2 not-conformant">Fail</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 partially-conformant">Partial</th>
</tr>
<tr><th class="column" colspan="5">
<a class="test_group" href="https://typing.readthedocs.io/en/latest/spec/generics.html">Generics</a>
Expand Down Expand Up @@ -281,7 +281,7 @@ <h3>Python Type System Conformance Test Results</h3>
<th class="column col2 conformant">Pass</th>
</tr>
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_paramspec_basic</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 partially-conformant">Partial</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
Expand Down
2 changes: 2 additions & 0 deletions conformance/results/zuban/specialtypes_type.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ specialtypes_type.py:143: error: "_SpecialForm" has no attribute "unknown" [att
specialtypes_type.py:144: error: "_SpecialForm" has no attribute "unknown" [attr-defined]
specialtypes_type.py:145: error: "_SpecialForm" has no attribute "unknown" [attr-defined]
specialtypes_type.py:146: error: "_SpecialForm" has no attribute "unknown" [attr-defined]
specialtypes_type.py:179: error: Invalid type [valid-type]
specialtypes_type.py:180: error: type[...] can't contain "Literal[...]" [misc]
"""
7 changes: 6 additions & 1 deletion conformance/tests/specialtypes_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Specification: https://typing.readthedocs.io/en/latest/spec/special-types.html#type


from typing import Any, Callable, Generic, Type, TypeAlias, TypeVar, assert_type
from typing import Any, Callable, Generic, Type, TypeAlias, TypeVar, assert_type, Literal, TypedDict


class User:
Expand Down Expand Up @@ -173,3 +173,8 @@ def func13(v: type):
class ClassA(Generic[T]):
def method1(self, v: type) -> type[T]:
return v # OK

# > Some other special forms like Literal and TypedDict are not allowed as an argument to type.
c: type[Callable] # OK
t: type[TypedDict] # E
l: type[Literal[1]] # E
4 changes: 2 additions & 2 deletions docs/spec/special-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ concrete class object, e.g. in the above example::
``type[T]`` where ``T`` is a type variable is allowed when annotating the
first argument of a class method (see the relevant section).

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

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