Skip to content

STYLE, TYP Turn black formatter off for overloads #40973

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

Closed

Conversation

MarcoGorelli
Copy link
Member

Following on from the monthly meeting's discussion, some things were suggested:

  • turning off the black formatter for the overloads, keeping them in .py files (what I've done here)
  • moving overloads to .pyi files, writing a script to keep them in sync (I tried that this, and it seems that mypy behaves a bit differently with a .pyi file than it does with a .py file - will look into this more closely, but it'll take more time)
  • keeping overloads out of .py files and "injecting" them before running mypy via a script - IMO this might be slightly disruptive to the usual workflow of just running mypy pandas, but other than that seems like a potentially good idea
  • doing away with overloads, and just using cast and assert - TBH this strikes me as more error-prone, and if pandas will expose types to users, then I think it'd be better to have the correct type revealed rather than having them do cast / assert

Even if inplace is removed in version 2, there are other places in the codebase where there's a parameter which changes the return type, so I do think finding a solution here is worthwhile.

For now, I've gone with the first solution, though I will give some more thought to the second one

@MarcoGorelli MarcoGorelli added the Typing type annotations, mypy/pyright type checking label Apr 16, 2021
@pep8speaks

This comment has been minimized.

@MarcoGorelli
Copy link
Member Author

looks like pep8speaks doesn't respect noqa...

@MarcoGorelli
Copy link
Member Author

looks like pep8speaks doesn't respect noqa...

any objections to removing pep8speaks? We already fail CI if flake8 fails, so I'm not sure what value it adds

...


def take_nd(arr: np.ndarray, indexer, axis: int = ..., fill_value=..., allow_fill: bool = ...) -> np.ndarray: ... # noqa
@overload
Copy link
Member

Choose a reason for hiding this comment

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

can the noqa be made specific, i think # noqa:F501,E704

Copy link
Member Author

Choose a reason for hiding this comment

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

done, thanks!

@simonjayhawkins
Copy link
Member

I think I prefer the status quo

@MarcoGorelli
Copy link
Member Author

Sure, let's stick to that then 👍

@MarcoGorelli MarcoGorelli deleted the fmt-off-for-overloads branch April 25, 2021 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants