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 couple inconsistencies in protocols vs TypeType#19267

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
ilevkivskyi merged 2 commits intopython:masterfromilevkivskyi:proto-type-edge-case
Jun 11, 2025
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
Fix couple inconsistencies in protocols vs TypeType
  • Loading branch information
@ilevkivskyi
ilevkivskyi committedJun 10, 2025
commitdd39282b21860303d2397ae484d9de9b845e5e06
2 changes: 1 addition & 1 deletionmypy/checker.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7190,7 +7190,7 @@ def check_subtype(
if (
isinstance(supertype, Instance)
and supertype.type.is_protocol
and isinstance(subtype, (CallableType, Instance, TupleType, TypedDictType))
and isinstance(subtype, (CallableType, Instance, TupleType, TypedDictType, TypeType))
):
self.msg.report_protocol_problems(subtype, supertype, context, code=msg.code)
if isinstance(supertype, CallableType) and isinstance(subtype, Instance):
Expand Down
11 changes: 8 additions & 3 deletionsmypy/messages.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3109,9 +3109,14 @@ def get_bad_protocol_flags(
assert right.type.is_protocol
all_flags: list[tuple[str, set[int], set[int]]] = []
for member in right.type.protocol_members:
if find_member(member, left, left):
item = (member, get_member_flags(member, left), get_member_flags(member, right))
all_flags.append(item)
if find_member(member, left, left, class_obj=class_obj):
all_flags.append(
(
member,
get_member_flags(member, left, class_obj=class_obj),
get_member_flags(member, right),
)
)
bad_flags = []
for name, subflags, superflags in all_flags:
if (
Expand Down
4 changes: 2 additions & 2 deletionsmypy/subtypes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1319,8 +1319,8 @@ def find_member(
is_lvalue=is_lvalue,
is_super=False,
is_operator=is_operator,
original_type=itype,
self_type=subtype,
original_type=TypeType.make_normalized(itype) if class_obj elseitype,
self_type=TypeType.make_normalized(subtype) if class_obj elsesubtype,
context=Context(), # all errors are filtered, but this is a required argument
chk=type_checker,
suppress_errors=True,
Expand Down
26 changes: 26 additions & 0 deletionstest-data/unit/check-protocols.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4551,3 +4551,29 @@ class Test(Generic[T]):
t = Test(Mock())
reveal_type(t) # N: Revealed type is "__main__.Test[Any]"
[builtins fixtures/dict.pyi]

[case testProtocolClassObjectDescriptor]
from typing import Any, Protocol, overload

class Desc:
@overload
def __get__(self, instance: None, owner: Any) -> Desc: ...
@overload
def __get__(self, instance: object, owner: Any) -> int: ...
def __get__(self, instance, owner):
pass

class HasDesc(Protocol):
attr: Desc

class HasInt(Protocol):
attr: int

class C:
attr = Desc()

x: HasInt = C()
y: HasDesc = C
z: HasInt = C # E: Incompatible types in assignment (expression has type "type[C]", variable has type "HasInt") \
# N: Following member(s) of "C" have conflicts: \
# N: attr: expected "int", got "Desc"

[8]ページ先頭

©2009-2025 Movatter.jp