Skip to content

Update __new__ method to use Self type for improved type hinting #918

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 6 commits into from
Apr 11, 2025

Conversation

fleming79
Copy link
Contributor

Recently Pylance (Pyright) started producing Any as the type hint for HasTraits objects since Pylance v 2025.2.102 & Pyright v 1.1.395. This may be related to the first dot point in the Pyright release notes here: https://github.com/microsoft/pyright/releases/tag/1.1.395.

Before

image

After

image

Reference: https://typing.python.org/en/latest/spec/constructors.html#consistency-of-new-and-init

cls = args[0]
args = args[1:]

def __new__(cls, /, *args: t.Any, **kwargs: t.Any) -> Self:
Copy link
Contributor Author

@fleming79 fleming79 Mar 9, 2025

Choose a reason for hiding this comment

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

@minrk minrk merged commit 945250c into ipython:main Apr 11, 2025
30 of 31 checks passed
@minrk
Copy link
Member

minrk commented Apr 11, 2025

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants