Skip to content

Fix self-referential upper bound in new-style type variables #17407

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

Merged
merged 2 commits into from
Jun 20, 2024
Merged
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
Merge branch 'master' into fix-type-var-bound
  • Loading branch information
JelleZijlstra authored Jun 20, 2024
commit 690252764c3d99a5c783aadb4c29c3e28113fd3f
52 changes: 52 additions & 0 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -1604,3 +1604,55 @@ class Good:

x: Comparable[Good]
y: Comparable[int] # E: Type argument "int" of "Comparable" must be a subtype of "Comparable[Any]"

[case testPEP695TypeAliasWithDifferentTargetTypes]
# flags: --enable-incomplete-feature=NewGenericSyntax
import types # We need GenericAlias from here, and test stubs don't bring in 'types'
from typing import Any, Callable, List, Literal, TypedDict

# Test that various type expressions don't generate false positives as type alias
# values, as they are type checked as expressions. There is a similar test case in
# pythoneval.test that uses typeshed stubs.

class C[T]: pass

class TD(TypedDict):
x: int

type A1 = type[int]
type A2 = type[int] | None
type A3 = None | type[int]
type A4 = type[Any]

type B1[**P, R] = Callable[P, R] | None
type B2[**P, R] = None | Callable[P, R]
type B3 = Callable[[str], int]
type B4 = Callable[..., int]

type C1 = A1 | None
type C2 = None | A1

type D1 = Any | None
type D2 = None | Any

type E1 = List[int]
type E2 = List[int] | None
type E3 = None | List[int]

type F1 = Literal[1]
type F2 = Literal['x'] | None
type F3 = None | Literal[True]

type G1 = tuple[int, Any]
type G2 = tuple[int, Any] | None
type G3 = None | tuple[int, Any]

type H1 = TD
type H2 = TD | None
type H3 = None | TD

type I1 = C[int]
type I2 = C[Any] | None
type I3 = None | C[TD]
[builtins fixtures/type.pyi]
[typing fixtures/typing-full.pyi]
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.