Uh oh!
There was an error while loading. Please reload this page.
Backport python/cpython#31628 - #119
Closed
Gobot1234 wants to merge 1 commit into
Closed
Conversation
JelleZijlstra
self-requested a review
February 21, 2023 00:48
JelleZijlstra
commented
Feb 21, 2023
Member
cc @adriangb if you're interested. |
JelleZijlstra
commented
Mar 6, 2023
Member
Looking at some of the failing tests:
|
Member
@Gobot1234, following recent changes I've made to diff --git a/src/test_typing_extensions.py b/src/test_typing_extensions.py
index 3a483b5..6fcfafb 100644
--- a/src/test_typing_extensions.py+++ b/src/test_typing_extensions.py@@ -1454,6 +1454,32 @@ class ProtocolTests(BaseTestCase):
class CG(PG[T]): pass
self.assertIsInstance(CG[int](), CG)
+ def test_protocol_defining_init_does_not_get_overridden(self):+ # check that P.__init__ doesn't get clobbered+ # see https://bugs.python.org/issue44807++ class P(Protocol):+ x: int+ def __init__(self, x: int) -> None:+ self.x = x+ class C: pass++ c = C()+ P.__init__(c, 1)+ self.assertEqual(c.x, 1)++ def test_concrete_class_inheriting_init_from_protocol(self):+ class P(Protocol):+ x: int+ def __init__(self, x: int) -> None:+ self.x = x++ class C(P): pass++ c = C(1)+ self.assertIsInstance(c, C)+ self.assertEqual(c.x, 1)+
def test_cannot_instantiate_abstract(self):
@runtime_checkable
class P(Protocol):
diff --git a/src/typing_extensions.py b/src/typing_extensions.py
index c28680c..94218ac 100644
--- a/src/typing_extensions.py+++ b/src/typing_extensions.py@@ -662,7 +662,8 @@ else:
isinstance(base, _ProtocolMeta) and base._is_protocol):
raise TypeError('Protocols can only inherit from other'
f' protocols, got {repr(base)}')
- cls.__init__ = _no_init+ if cls.__init__ is Protocol.__init__:+ cls.__init__ = _no_init |
Gobot1234
commented
Apr 12, 2023
ContributorAuthor
I may have forgotten about this PR 😅. That does look a lot nicer though. |
AlexWaygood
commented
Apr 13, 2023
Member
Happy to take over if you like, or leave it to you -- whatever you prefer :) |
Gobot1234
commented
Apr 13, 2023
ContributorAuthor
If you already have it working that'd be great, thank you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Needs decision on how to fix failing test
Fixes#104