| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…th deferred annotations
There was a problem hiding this comment.
Thank you!
Sorry, something went wrong.
| x: undefined | ||
|
|
||
| self.assertFalse(isinstance(DeferredClass(), P)) | ||
|
|
There was a problem hiding this comment.
Also add a test with a class that does fulfill the protocol.
Also, please add a NEWS entry.
Sorry, something went wrong.
There was a problem hiding this comment.
I added a class that satisfies the protocol and a NEWS entry:)
Sorry, something went wrong.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
…aranteed Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
| annotations = _lazy_annotationlib.get_annotations(base, format=_lazy_annotationlib.Format.FORWARDREF) | ||
| if (attr in annotations | ||
| and issubclass(other, Generic) | ||
| and getattr(other, '_is_protocol', False)): |
There was a problem hiding this comment.
We can probably gain some performance by doing the issubclass() and getattr() checks before doing the annotations check, since they should be fast and for most use cases they'll return False (it's surely more common to do isinstance(<non protocol>, Protocol), not isinstance(<other protocol>, Protocol)).
Sorry, something went wrong.
There was a problem hiding this comment.
I moved the issubclass() and geattr() checks up:)
Sorry, something went wrong.
There was a problem hiding this comment.
With the new order of conditions we could also move the call to _lazy_annotationlib.get_annotations so we only do that in case the other two conditions are true, what do you think?
Like this:
if (
issubclass(other, Generic)
and getattr(other, "_is_protocol", False)
and attr in _lazy_annotationlib.get_annotations(base, format=_lazy_annotationlib.Format.FORWARDREF)
):
Sorry, something went wrong.
| meth: undefined | ||
|
|
||
|
|
||
| self.assertTrue(issubclass(SubProtocol, P)) |
There was a problem hiding this comment.
These can use helpers assertIsSubclass, assertIsInstance, assertNotIsinstance.
Sorry, something went wrong.
There was a problem hiding this comment.
Updated it to use the helper methods
Sorry, something went wrong.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
| Back | FazBrowse Home | New Git URL |
Hi, this is in regards to #132493. This PR avoids eager evaluation of annotations during isinstance checks for protocols.