Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Prevent crash with Unpack of a fixed tuple in PEP695 type alias#18451

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 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
NextNext commit
Do not call get_proper_type for traversing type alias: that creates a…
… copy preventing union items update.
  • Loading branch information
@sterliakov
sterliakov committedJan 13, 2025
commit0ceb6ada277292012b333d4923ceea89eb5f8227
2 changes: 1 addition & 1 deletionmypy/semanal_typeargs.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -101,7 +101,7 @@ def visit_type_alias_type(self, t: TypeAliasType) -> None:
if not is_error:
# If there was already an error for the alias itself, there is no point in checking
# the expansion, most likely it will result in the same kind of error.
get_proper_type(t).accept(self)
t.alias.target.accept(self)

def visit_tuple_type(self, t: TupleType) -> None:
t.items = flatten_nested_tuples(t.items)
Expand Down
16 changes: 16 additions & 0 deletionstest-data/unit/check-python312.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1972,3 +1972,19 @@ class D:
class G[Q]:
def g(self, x: Q): ...
d: G[str]

[case testTypeAliasNormalization]
from collections.abc import Callable
from typing import Unpack
from typing_extensions import TypeAlias

type RK_function_args = tuple[float, int]
type RK_functionBIS = Callable[[Unpack[RK_function_args], int], int]

def ff(a: float, b: int, c: int) -> int:
return 2

bis: RK_functionBIS = ff
res: int = bis(1.0, 2, 3)
[builtins fixtures/tuple.pyi]
[typing fixtures/typing-full.pyi]
13 changes: 9 additions & 4 deletionstest-data/unit/check-type-aliases.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -977,13 +977,18 @@ class C(Generic[T]): ...
class D(C[S]): ... # E: Invalid type argument value for "C"

U = TypeVar("U")
A = List[C[U]]
x: A[bytes] # E: Value of type variable "T" of "C" cannot be "bytes"
A = List[C[U]] # E: Type variable "U" not valid as type argument value for "C"
A2 = List[C[T]]
x: A[bytes]
x2: A2[bytes] # E: Value of type variable "T" of "A2" cannot be "bytes"

V = TypeVar("V", bound=int)
V2 = TypeVar("V2", bound=int)
class E(Generic[V]): ...
B = List[E[U]]
y: B[str] # E: Type argument "str" of "E" must be a subtype of "int"
B = List[E[U]] # E: Type argument "U" of "E" must be a subtype of "int"
B2 = List[E[V2]]
y: B[str]
y2: B2[str] # E: Type argument "str" of "B2" must be a subtype of "int"

[case testValidTypeAliasValuesMoreRestrictive]
from typing import TypeVar, Generic, List
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp