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

gh-102433: Add tests for how classes with properties interact withisinstance() checks ontyping.runtime_checkable protocols#102449

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
AlexWaygood merged 6 commits intopython:mainfromAlexWaygood:runtime-checkable-tests
Mar 11, 2023

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygoodAlexWaygood commentedMar 5, 2023
edited
Loading

It appears we currently have no tests for how classes with properties interact withisinstance checks for protocols decorated with@runtime_checkable.

I'm trying to only add tests here for uncontroversial behaviour that we won't want changed, whether or not any of the patches discussed inpython/typing#1363 is implemented.

@AlexWaygood
Copy link
MemberAuthor

Marking as "DO-NOT-MERGE" for now, as this appears more controversial than I realised.

@AlexWaygoodAlexWaygood marked this pull request as draftMarch 6, 2023 11:29
@AlexWaygoodAlexWaygood marked this pull request as ready for reviewMarch 10, 2023 17:06
@AlexWaygood
Copy link
MemberAuthor

I've removed the tests that assert undesirable behaviour, as per the consensus inpython/typing#1363.

classC:
@property
defattr(self):
return42
Copy link
Member

Choose a reason for hiding this comment

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

What about side-effects in@property likeraise ValueError? Should we test this case?

Copy link
MemberAuthor

@AlexWaygoodAlexWaygoodMar 10, 2023
edited
Loading

Choose a reason for 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 inpython/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.

Copy link
Member

@carljmcarljm left a comment

Choose a reason for 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!

AlexWaygood reacted with hooray emoji
classBadPG1(Protocol[T]):
attr:T

forobjinPG[T],PG[C],PG1[T],PG1[C],BadP,BadP1,BadPG,BadPG1:
Copy link
Member

Choose a reason for 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 nameobj

Copy link
MemberAuthor

@AlexWaygoodAlexWaygoodMar 11, 2023
edited
Loading

Choose a reason for 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'tstrictly speaking classes anymore — they're generic aliases to protocol classes.

carljm reacted with thumbs up emoji
Co-authored-by: Carl Meyer <carl@oddbird.net>
@AlexWaygoodAlexWaygood merged commit5ffdaf7 intopython:mainMar 11, 2023
@miss-islington
Copy link
Contributor

Thanks@AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

@AlexWaygoodAlexWaygood deleted the runtime-checkable-tests branchMarch 11, 2023 01:20
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMar 11, 2023
…ith `isinstance()` checks on `typing.runtime_checkable` protocols (pythonGH-102449)(cherry picked from commit5ffdaf7)Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>Co-authored-by: Carl Meyer <carl@oddbird.net>
@bedevere-bot
Copy link

GH-102592 is a backport of this pull request to the3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11only security fixes labelMar 11, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMar 11, 2023
…ith `isinstance()` checks on `typing.runtime_checkable` protocols (pythonGH-102449)(cherry picked from commit5ffdaf7)Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>Co-authored-by: Carl Meyer <carl@oddbird.net>
@bedevere-bot
Copy link

GH-102593 is a backport of this pull request to the3.10 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.10only security fixes labelMar 11, 2023
@AlexWaygood
Copy link
MemberAuthor

Thanks, all!

miss-islington added a commit that referenced this pull requestMar 11, 2023
…sinstance()` checks on `typing.runtime_checkable` protocols (GH-102449)(cherry picked from commit5ffdaf7)Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>Co-authored-by: Carl Meyer <carl@oddbird.net>
miss-islington added a commit that referenced this pull requestMar 11, 2023
…sinstance()` checks on `typing.runtime_checkable` protocols (GH-102449)(cherry picked from commit5ffdaf7)Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>Co-authored-by: Carl Meyer <carl@oddbird.net>
iritkatriel pushed a commit to iritkatriel/cpython that referenced this pull requestMar 12, 2023
…ith `isinstance()` checks on `typing.runtime_checkable` protocols (python#102449)Co-authored-by: Carl Meyer <carl@oddbird.net>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@carljmcarljmcarljm approved these changes

@gvanrossumgvanrossumAwaiting requested review from gvanrossum

@Fidget-SpinnerFidget-SpinnerAwaiting requested review from Fidget-Spinner

@JelleZijlstraJelleZijlstraAwaiting requested review from JelleZijlstraJelleZijlstra is a code owner

@sobolevnsobolevnAwaiting requested review from sobolevn

Assignees

No one assigned

Labels

skip newstestsTests in the Lib/test dir

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@AlexWaygood@miss-islington@bedevere-bot@carljm@JelleZijlstra@sobolevn

[8]ページ先頭

©2009-2025 Movatter.jp