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

Backport some recentProtocol fixes from 3.12#161

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
JelleZijlstra merged 3 commits intopython:mainfromAlexWaygood:proto-fixes
May 19, 2023

Conversation

Comment on lines +2401 to +2438
exec(textwrap.dedent(
"""
def test_pep695_generic_protocol_callable_members(self):
@runtime_checkable
class Foo[T](Protocol):
def meth(self, x: T) -> None: ...
class Bar[T]:
def meth(self, x: T) -> None: ...
self.assertIsInstance(Bar(), Foo)
self.assertIsSubclass(Bar, Foo)
@runtime_checkable
class SupportsTrunc[T](Protocol):
def __trunc__(self) -> T: ...
self.assertIsInstance(0.0, SupportsTrunc)
self.assertIsSubclass(float, SupportsTrunc)
def test_no_weird_caching_with_issubclass_after_isinstance_pep695(self):
@runtime_checkable
class Spam[T](Protocol):
x: T
class Eggs[T]:
def __init__(self, x: T) -> None:
self.x = x
self.assertIsInstance(Eggs(42), Spam)
# gh-104555: If we didn't override ABCMeta.__subclasscheck__ in _ProtocolMeta,
# TypeError wouldn't be raised here,
# as the cached result of the isinstance() check immediately above
# would mean the issubclass() call would short-circuit
# before we got to the "raise TypeError" line
with self.assertRaises(TypeError):
issubclass(Eggs, Spam)
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ithink these pass, but had no way of checking, sincetyping_extensions currently fails to import on 3.12:

Traceback (most recent call last):  File "C:\Users\alexw\coding\typing_extensions\src\test_typing_extensions.py", line 29, in <module>    import typing_extensions  File "C:\Users\alexw\coding\typing_extensions\src\typing_extensions.py", line 1361, in <module>    class TypeVar(typing.TypeVar, _DefaultMixin, _root=True):TypeError: type 'typing.TypeVar' is not an acceptable base type

@AlexWaygood
Copy link
MemberAuthor

Oh, the PyPy version ofABCMeta results in a bunch of extra attributes being present in a class's__dict__? TIL.

@AlexWaygood
Copy link
MemberAuthor

Oh, the PyPy version ofABCMeta results in a bunch of extra attributes being present in a class's__dict__? TIL.

Ugh, that means we'll probably have to mark the test in CPython as@cpython_only.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@AlexWaygood@JelleZijlstra

[8]ページ先頭

©2009-2025 Movatter.jp