-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Remove ABC Usage from pandas._typing #27146
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
Comments
what if we use the quoted imports eg ‘DataFrame’? doesn’t this achieve the same purpose? |
In pandas._typing or in other modules? This code: some_obj = None # type: 'pd.DataFrame'
reveal_type(some_obj) Yields: test.py:1: error: Name 'pd' is not defined
test.py:2: note: Revealed type is 'Any' |
You can avoid circular imports by guarding the imports in In xarray we wrote a little stub for |
does just ‘DataFrame’ or ‘pandas.core.frame.DataFrame’ work? |
Right but IIUC we would then need to use that in all modules importing
no those would yield |
Right now we use the ABC classes in pandas._typing to work around circular imports, but I think this has the effect of making our type checking practically non-existent. The ABCs are factory generated by an unannotated function, so they get replaced with
Any
To illustrate, run mypy on a module with this content
Mypy runs without issue yielding
By contrast, using the actual DataFrame class:
Yields an error:
I'm not sure the best approach here. Direct imports into pandas._typing should cause circular imports but the ABCs won't provide anything with type checking as long as they are factory generated.
The text was updated successfully, but these errors were encountered: