Skip to content

avoid a warning by PyTypeChecker #44478

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
wants to merge 3 commits into from

Conversation

foreverseer
Copy link

@foreverseer foreverseer commented Nov 16, 2021

NDFrame.to_csv(str) got a warning by PyTypeChecker, "Expected type 'None', got 'str' instead"
use typing.Union to combine type "FilePathOrBuffer[AnyStr]" and "None", instead of " | " can avoid it.
image

  • closes #xxxx
  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them
  • whatsnew entry

NDFrame.to_csv(str) got a warning by PyTypeChecker, "Expected type 'None', got 'str' instead"
use typing.Union to combine type "FilePathOrBuffer[AnyStr]" and "None", instead of " | " can avoid it.
@pep8speaks
Copy link

pep8speaks commented Nov 16, 2021

Hello @foreverseer! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-11-16 01:40:18 UTC

"from typing import Union " with wrong place in last commit
@twoertwein
Copy link
Member

If PyTypeChecker cannot handle |, then it might be worth to open a bug at PyTypeChecker? Pandas is not yet a py.typed library, can you double-check that PyTypeChecker is getting the type annotations from pandas (or a third-party stub file)?

Do you mind testing whether PyTypeChecker still has the issue on master? You are welcome to also test PyTypeChecker with #43951.

@foreverseer
Copy link
Author

If PyTypeChecker cannot handle |, then it might be worth to open a bug at PyTypeChecker? Pandas is not yet a py.typed library, can you double-check that PyTypeChecker is getting the type annotations from pandas (or a third-party stub file)?

Do you mind testing whether PyTypeChecker still has the issue on master? You are welcome to also test PyTypeChecker with #43951.

pytypechecker is a function of pycharm
i mean not use Union to combine two type will cause a warning of pycharm
image
↑this is pycharm's warning

@twoertwein
Copy link
Member

twoertwein commented Nov 16, 2021

pandas/core/generic.py uses the python 3.10+ syntax | (equivalent to typing.Union) and also has from __future__ import annotations which enables this syntax for older versions of python.

I recomend opening a bug with pycharm (after checking that pycharm is using the tpye annotations shipped with pandas itself - most likely it uses 3rd-party type stubs).

@mroeschke
Copy link
Member

Agreed, pandas uses | instead of Union consistently in the code base so it appears that this is more of an upstream issue. Closing.

@mroeschke mroeschke closed this Nov 16, 2021
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.

5 participants