GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-102433: Add tests for how classes with properties interact with `isinstance()` checks on `typing.runtime_checkable` protocols by AlexWaygood · Pull Request #102449 · python/cpython Conversation
|
|
Marking as "DO-NOT-MERGE" for now, as this appears more controversial than I realised. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I've removed the tests that assert undesirable behaviour, as per the consensus in python/typing#1363. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| class C: | ||
| @property | ||
| def attr(self): | ||
| return 42 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What about side-effects in @property like raise ValueError? Should we test this case?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We should test this case, definitely! But the behaviour for this case may be about to change if any of the patches discussed in python/typing#1363 is implemented (and the consensus seems to be that we should implement one of those patches). If so, we should add the tests in the same PR as we change the behaviour.
Whether or not we decide to change the behaviour around properties that have side effects, I'd prefer to add those tests in a separate PR, so that this PR is solely focussed on adding tests for uncontroversial behaviour.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A couple nits, but these tests look good to me! Thank you!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| class BadPG1(Protocol[T]): | ||
| attr: T | ||
|
|
||
| for obj in PG[T], PG[C], PG1[T], PG1[C], BadP, BadP1, BadPG, BadPG1: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
nit: these are all protocol classes still; the name 'protocol_class used in the above "good" loop seems much clearer than the name obj
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
No strong opinion here, but the reason I avoided "protocol_class" for these ones is that the parameterised ones (PG[T], etc) aren't strictly speaking classes anymore — they're generic aliases to protocol classes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Carl Meyer <[email protected]>
|
Thanks @AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ith `isinstance()` checks on `typing.runtime_checkable` protocols (pythonGH-102449) (cherry picked from commit 5ffdaf7) Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Carl Meyer <[email protected]>
|
GH-102592 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ith `isinstance()` checks on `typing.runtime_checkable` protocols (pythonGH-102449) (cherry picked from commit 5ffdaf7) Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Carl Meyer <[email protected]>
|
GH-102593 is a backport of this pull request to the 3.10 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks, all! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…sinstance()` checks on `typing.runtime_checkable` protocols (GH-102449) (cherry picked from commit 5ffdaf7) Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Carl Meyer <[email protected]>
…sinstance()` checks on `typing.runtime_checkable` protocols (GH-102449) (cherry picked from commit 5ffdaf7) Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Carl Meyer <[email protected]>
…ith `isinstance()` checks on `typing.runtime_checkable` protocols (python#102449) Co-authored-by: Carl Meyer <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.