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

Fix attribute type resolution with multiple inheritance#18415

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
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
Map TypeVar-valued attributes to the checked base
  • Loading branch information
@sterliakov
sterliakov committedJan 4, 2025
commite8ccf89ec17a34cf04df26e520f23d0ec68a7d53
2 changes: 2 additions & 0 deletionsmypy/checker.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2826,8 +2826,10 @@ class C(B, A[int]): ... # this is unsafe because...
ok = is_subtype(first_sig, second_sig, ignore_pos_arg_names=True)
elif first_type and second_type:
if isinstance(first.node, Var):
first_type = map_type_from_supertype(first_type, ctx, base1)
first_type = expand_self_type(first.node, first_type, fill_typevars(ctx))
if isinstance(second.node, Var):
second_type = map_type_from_supertype(second_type, ctx, base2)
second_type = expand_self_type(second.node, second_type, fill_typevars(ctx))
ok = is_equivalent(first_type, second_type)
if not ok:
Expand Down
36 changes: 36 additions & 0 deletionstest-data/unit/check-generic-subtyping.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1065,3 +1065,39 @@ class F(E[T_co], Generic[T_co]): ... # E: Variance of TypeVar "T_co" incompatib

class G(Generic[T]): ...
class H(G[T_contra], Generic[T_contra]): ... # E: Variance of TypeVar "T_contra" incompatible with variance in parent type

[case testMultipleInheritanceCompatibleTypeVar]
from typing import Generic, TypeVar

T = TypeVar("T")
U = TypeVar("U")

class A(Generic[T]):
x: T
def fn(self, t: T) -> None: ...

class A2(A[T]):
y: str
z: str

class B(Generic[T]):
x: T
def fn(self, t: T) -> None: ...

class C1(A2[str], B[str]): pass
class C2(A2[str], B[int]): pass # E: Definition of "x" in base class "A" is incompatible with definition in base class "B" \
# E: Definition of "fn" in base class "A" is incompatible with definition in base class "B"
class C3(A2[T], B[T]): pass
class C4(A2[U], B[U]): pass
class C5(A2[U], B[T]): pass # E: Definition of "x" in base class "A" is incompatible with definition in base class "B" \
# E: Definition of "fn" in base class "A" is incompatible with definition in base class "B"

class D1(A[str], B[str]): pass
class D2(A[str], B[int]): pass # E: Definition of "x" in base class "A" is incompatible with definition in base class "B" \
# E: Definition of "fn" in base class "A" is incompatible with definition in base class "B"
class D3(A[T], B[T]): pass
class D4(A[U], B[U]): pass
class D5(A[U], B[T]): pass # E: Definition of "x" in base class "A" is incompatible with definition in base class "B" \
# E: Definition of "fn" in base class "A" is incompatible with definition in base class "B"

[builtins fixtures/tuple.pyi]

[8]ページ先頭

©2009-2025 Movatter.jp