Skip to content

Refactor a test#100434

Closed
JosephSBoyle wants to merge 2 commits intopython:mainfrom
JosephSBoyle:simplify-subclasshook-test
Closed

Refactor a test#100434
JosephSBoyle wants to merge 2 commits intopython:mainfrom
JosephSBoyle:simplify-subclasshook-test

Conversation

@JosephSBoyle
Copy link
Copy Markdown
Contributor

@JosephSBoyle JosephSBoyle commented Dec 22, 2022

Changes:

  • Refactors out the 'if bool: return True; else: return False` anti-pattern.
  • Makes Base inherit from abc.ABC instead of typing.Iterable, which is a clearer statement of intent. (Edit: this was a misunderstanding on my part).

Not creating an issue as I don't think this warrants one.
Not creating a News entry as I don't think this warrants one.

@bedevere-bot
Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ghost
Copy link
Copy Markdown

ghost commented Dec 22, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

def test_subclassing_subclasshook(self):

class Base(typing.Iterable):
class Base(abc.ABC):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you've misunderstood the intent of this test, I'm afraid.

If the intent of this test was to check that custom __subclasshook__ methods worked on subclasses of abc.ABC, then this test would be in test_abc.py, not test_typing.py. I believe the intent of this test is to check that subclasses of typing.Iterable (and other collections.abc aliases in typing.py) can define custom __subclasshook__ methods in the same way as the "original" classes in collections.abc, despite the fact that typing.Iterable isn't actually a class in the same way that collections.abc.Iterable is:

>>> import typing
>>> type(typing.Iterable)
<class 'typing._SpecialGenericAlias'>

So, far from clarifying the intent of this test, I'm afraid this change turns it from being a useful test into a somewhat useless test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also note that this test is found in a class called CollectionsAbcTests. It would be strange to have a test found in this class that didn't pertain specifically to an alias for a class from collections.abc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clarifying @AlexWaygood, I've reverted that particular change.

@bedevere-bot
Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@bedevere-bot
Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@JosephSBoyle JosephSBoyle requested review from AlexWaygood and removed request for Fidget-Spinner, JelleZijlstra and gvanrossum December 22, 2022 14:50
@AlexWaygood
Copy link
Copy Markdown
Member

The remaining change is purely cosmetic. I'm afraid CPython's policy is generally to reject PRs that make purely cosmetic changes, as they just lead to code churn, obscuring git history.

Sorry to be a grouch this close to Christmas, but I think I'll close this PR, since it isn't solving an actual problem of any kind, as far as I can see :/

I hope this doesn't discourage you too much from contributing to CPython in the future! We have lots of open issues that need fixing, and 211 are currently marked with the easy label :)

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

Labels

awaiting changes tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants