8000 Add partial.__new__ by NeilGirdhar · Pull Request #6813 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Add partial.__new__ #6813

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2022
Merged

Add partial.__new__ #6813

merged 1 commit into from
Jan 4, 2022

Conversation

NeilGirdhar
Copy link
Contributor
@NeilGirdhar NeilGirdhar commented Jan 4, 2022
  • Add partial.__new__: __new__ is necessary for any derived classes that
    override __new__ and want to call super since __new__ instead of __init__ is
    defined in the base class.
  • Remove partial.__init__ since it's not defined.
  • Make the func parameter positional-only by naming it with
    double-underscore, as per PEP 484.

See: https://github.com/python/cpython/blob/main/Lib/functools.py#L283

@github-actions

This comment has been minimized.

* Add partial.__new__: __new__ is necessary for any derived classes that
  override __new__ and want to call super since new instead of init is
  defined in the base class.
* Remove partial.__init__ since it's not defined.
* Make the func parameter positional-only by naming it with
  double-underscore, as per PEP 484.
Copy link
Collaborator
@Akuli Akuli left a comment

Choose a reason for hiding this comment

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

This looks correct, although I'm not sure how much practical effect it has. Type checkers special-case functools.partial.

@Akuli
Copy link
Collaborator
Akuli commented Jan 4, 2022

Nit for future reference: Avoid amending and force-pushing when contributing to typeshed, because after a force-push, it's harder to see what has changed since the previous review. When merging the PR, we will use Github's "Squash and merge" button to combine the whole PR into a single commit on master.

@NeilGirdhar
Copy link
Contributor Author
NeilGirdhar commented Jan 4, 2022

This looks correct, although I'm not sure how much practical effect it has.

Thanks for the quick review. I tested that this change fixes my MyPy error here: https://github.com/NeilGirdhar/tjax/blob/master/tjax/_src/partial.py#L57

@github-actions
Copy link
Contributor
github-actions bot commented Jan 4, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@Akuli
Copy link
Collaborator
Akuli commented Jan 4, 2022

Nice! You may want to add the project to https://github.com/hauntsaninja/mypy_primer so that instead of getting the above "no effect" comment from mypy_primer, we would get something along the lines of "unused type: ignore comment".

@Akuli Akuli merged commit 9116b29 into python:master Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0