Skip to content

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