Skip to content

Replace aliases to builtins with imports #1244

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
Jun 7, 2025

Conversation

hamdanal
Copy link
Contributor

@hamdanal hamdanal commented Jun 7, 2025

  • Closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added: Please use assert_type() to assert the type of any return value

These aliases are not needed as they are there to avoid name collisions with methods defined in the class. Name collisions can be avoided by importing these symbols from builtins under a different name. This has no functional change to type checkers but has two tiny advantages:

  1. IDEs now display the type as builtin type instead of an alias that doesn't exist at runtime
  2. Linters like ruff can now understand that the symbol used is exactly the builtin one and can detect more bad usages (see the comment below)

Comment on lines -2151 to +2152
method: _str | FillnaOptions | Literal["nearest"] | None = ...,
method: FillnaOptions | Literal["nearest"] | None = ...,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ruff can now detect that _str shadows the literals we accept so it started complaining here

Copy link
Collaborator

Choose a reason for hiding this comment

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

and this is a better change because the set of strings that are accepted is limited

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

thanks @hamdanal

Comment on lines -2151 to +2152
method: _str | FillnaOptions | Literal["nearest"] | None = ...,
method: FillnaOptions | Literal["nearest"] | None = ...,
Copy link
Collaborator

Choose a reason for hiding this comment

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

and this is a better change because the set of strings that are accepted is limited

@Dr-Irv Dr-Irv merged commit 32fdfe4 into pandas-dev:main Jun 7, 2025
13 checks passed
@hamdanal hamdanal deleted the builtins-aliases branch June 7, 2025 15:28
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