Skip to content
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

Exclude the same special attributes from Protocol as CPython #15490

Merged
merged 6 commits into from
Jun 26, 2023
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
Next Next commit
Test __slots__ used as a protocol member
  • Loading branch information
HexDecimal committed Jun 21, 2023
commit 2966617f826e92a4c3134413dff50d6fc9dd4d87
36 changes: 36 additions & 0 deletions test-data/unit/check-protocols.test
Original file line number Diff line number Diff line change
Expand Up @@ -2789,6 +2789,42 @@ class A(Protocol):

[builtins fixtures/tuple.pyi]

[case testProtocolSlotsIsNotProtocolMember]
# https://github.com/python/mypy/issues/11884
from typing import Protocol

class Foo(Protocol):
__slots__ = ()
class NoSlots:
pass
class EmptySlots:
__slots__ = ()
class TupleSlots:
__slots__ = ('x', 'y')
class StringSlots:
__slots__ = 'x y'
def foo(f: Foo):
pass

# All should pass:
foo(NoSlots())
foo(EmptySlots())
foo(TupleSlots())
foo(StringSlots())
[builtins fixtures/tuple.pyi]

[case testProtocolSlotsAndRuntimeCheckable]
from typing import Protocol, runtime_checkable

@runtime_checkable
class Foo(Protocol):
__slots__ = ()
class Bar:
pass
issubclass(Bar, Foo) # Used to be an error, when `__slots__` counted as a protocol member
[builtins fixtures/isinstance.pyi]
[typing fixtures/typing-full.pyi]

[case testNoneVsProtocol]
# mypy: strict-optional
from typing_extensions import Protocol
Expand Down