8000 Specify that assert_type() uses equivalence by JelleZijlstra · Pull Request #2011 · python/typing · GitHub
[go: up one dir, main page]

Skip to content

Specify that assert_type() uses equivalence #2011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
updates
  • Loading branch information
JelleZijlstra committed Jun 29, 2025
commit 4e54113fa03247eb67946f405506aaf04960df28
3 changes: 2 additions & 1 deletion conformance/results/mypy/directives_assert_type.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
conformant = "Pass"
output = """
directives_assert_type.py:28: error: Expression is of type "int | str", not "int" [assert-type]
directives_assert_type.py:27: error: Expression is of type "int | str", not "int" [assert-type]
directives_assert_type.py:28: error: Expression is of type "int | str", not "Any" [assert-type]
directives_assert_type.py:29: error: Expression is of type "Any", not "int" [assert-type]
directives_assert_type.py:30: error: Expression is of type "Literal[4]", not "int" [assert-type]
directives_assert_type.py:32: error: "assert_type" expects 2 arguments [misc]
Expand Down
8 changes: 4 additions & 4 deletions conformance/results/pyre/directives_assert_type.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ conformant = "Pass"
notes = """
"""
output = """
directives_assert_type.py:22:4 Assert type [70]: Expected `Union[bool, int, str]` but got `Union[int, str]`.
directives_assert_type.py:28:4 Assert type [70]: Expected `int` but got `Union[int, str]`.
directives_assert_type.py:27:4 Assert type [70]: Expected `int` but got `Union[int, str]`.
directives_assert_type.py:28:4 Assert type [70]: Expected `typing.Any` but got `Union[int, str]`.
directives_assert_type.py:29:4 Assert type [70]: Expected `int` but got `typing.Any`.
directives_assert_type.py:30:4 Assert type [70]: Expected `int` but got `typing_extensions.Literal[4]`.
directives_assert_type.py:32:4 Missing argument [20]: Call `assert_type` expects argument in position 0.
directives_assert_type.py:33:4 Assert type [70]: Expected `int` but got `typing_extensions.Literal['']`.
directives_assert_type.py:34:4 Too many arguments [19]: Call `assert_type` expects 2 positional arguments, 3 were provided.
directives_assert_type.py:41:4 Assert type [70]: Expected `Union[typing_extensions.Literal['spam'], str]` but got `str`.
"""
conformance_automated = "Fail"
conformance_automated = "Pass"
errors_diff = """
Line 22: Unexpected errors ['directives_assert_type.py:22:4 Assert type [70]: Expected `Union[bool, int, str]` but got `Union[int, str]`.']
"""
10 changes: 8 additions & 2 deletions conformance/results/pyright/aliases_newtype.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ aliases_newtype.py:11:8 - error: Argument of type "Literal['user']" cannot be as
  "Literal['user']" is not assignable to "int" (reportArgumentType)
aliases_newtype.py:12:14 - error: Type "Literal[42]" is not assignable to declared type "UserId"
  "Literal[42]" is not assignable to "UserId" (reportAssignmentType)
aliases_newtype.py:18:11 - error: Type "type[UserId]" is not assignable to declared type "type"
  "FunctionType" is not assignable to "type" (reportAssignmentType)
aliases_newtype.py:23:16 - error: Argument of type "type[UserId]" cannot be assigned to parameter "class_or_tuple" of type "_ClassInfo" in function "isinstance"
  Type "FunctionType" is not assignable to type "_ClassInfo"
    "FunctionType" is not assignable to "type"
    "FunctionType" is not assignable to "UnionType"
    "FunctionType" is not assignable to "tuple[_ClassInfo, ...]" (reportArgumentType)
aliases_newtype.py:23:16 - error: Second argument to "isinstance" must be a class or tuple of classes
  Class created with NewType cannot be used with instance and class checks (reportArgumentType)
aliases_newtype.py:26:21 - error: Base class "UserId" is marked final and cannot be subclassed (reportGeneralTypeIssues)
Expand All @@ -20,7 +27,6 @@ aliases_newtype.py:61:38 - error: NewType cannot be used with structural type (a
aliases_newtype.py:63:15 - error: NewType requires two positional arguments (reportCallIssue)
aliases_newtype.py:65:38 - error: The second argument to NewType must be a known class, not Any or Unknown (reportGeneralTypeIssues)
"""
conformance_automated = "Fail"
conformance_automated = "Pass"
errors_diff = """
Line 18: Expected 1 errors
"""
8 changes: 4 additions & 4 deletions conformance/results/pyright/directives_assert_type.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ notes = """
Fails to treat equivalent unions as equivalent.
"""
output = """
directives_assert_type.py:22:17 - error: "assert_type" mismatch: expected "int | bool | str" but received "int | str" (reportAssertTypeFailure)
directives_assert_type.py:28:17 - error: "assert_type" mismatch: expected "int" but received "int | str" (reportAssertTypeFailure)
directives_assert_type.py:27:17 - error: "assert_type" mismatch: expected "int" but received "int | str" (reportAssertTypeFailure)
directives_assert_type.py:28:17 - error: "assert_type" mismatch: expected "Any" but received "int | str" (reportAssertTypeFailure)
directives_assert_type.py:29:17 - error: "assert_type" mismatch: expected "int" but received "Any" (reportAssertTypeFailure)
directives_assert_type.py:30:17 - error: "assert_type" mismatch: expected "int" but received "Literal[4]" (reportAssertTypeFailure)
directives_assert_type.py:32:5 - error: "assert_type" expects two positional arguments (reportCallIssue)
directives_assert_type.py:33:17 - error: "assert_type" mismatch: expected "int" but received "Literal['']" (reportAssertTypeFailure)
directives_assert_type.py:34:5 - error: "assert_type" expects two positional arguments (reportCallIssue)
directives_assert_type.py:41:17 - error: "assert_type" mismatch: expected "str | Literal['spam']" but received "str" (reportAssertTypeFailure)
"""
conformance_automated = "Fail"
conformance_automated = "Pass"
errors_diff = """
Line 22: Unexpected errors ['directives_assert_type.py:22:17 - error: "assert_type" mismatch: expected "int | bool | str" but received "int | str" (reportAssertTypeFailure)']
"""
4 changes: 2 additions & 2 deletions conformance/results/pyright/generics_type_erasure.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ generics_type_erasure.py:42:11 - error: Access to generic instance variable thro
generics_type_erasure.py:43:11 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
generics_type_erasure.py:44:6 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
generics_type_erasure.py:45:6 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
generics_type_erasure.py:46:10 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
"""
conformance_automated = "Fail"
conformance_automated = "Pass"
errors_diff = """
Line 46: Expected 1 errors
"""
2 changes: 1 addition & 1 deletion conformance/results/pyright/protocols_definition.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protocols_definition.py:160:22 - error: Type "Concrete3_Bad5" is not assignable
protocols_definition.py:218:22 - error: Type "Concrete4_Bad1" is not assignable to declared type "Template4"
  "Concrete4_Bad1" is incompatible with protocol "Template4"
    "val1" is an incompatible type
      "FunctionType" is not assignable to "Sequence[float]" (reportAssignmentType)
      "MethodType" is not assignable to "Sequence[float]" (reportAssignmentType)
protocols_definition.py:219:22 - error: Type "Concrete4_Bad2" is not assignable to declared type "Template4"
  "Concrete4_Bad2" is incompatible with protocol "Template4"
    "val1" is not present (reportAssignmentType)
Expand Down
0