Skip to content

TYP: enable reportMissingImports #43790

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 7 commits into from
Oct 6, 2021
Merged

TYP: enable reportMissingImports #43790

merged 7 commits into from
Oct 6, 2021

Conversation

twoertwein
Copy link
Member

@twoertwein twoertwein commented Sep 28, 2021

reportMissingImports checks whether all libraries can be imported. This requires all dependencies to be installed on the CI that runs pyright.

This flag should probably NOT be enabled, as it would force all contributors to install all dependencies. I'm enabling it temporarily to see whether the CI has all dependencies installed.

edit:
The typing CI has not all packages installed:

/home/runner/work/pandas/pandas/pandas/io/clipboard/__init__.py
  /home/runner/work/pandas/pandas/pandas/io/clipboard/__init__.py:150:14 - error: Import "qtpy.QtWidgets" could not be resolved (reportMissingImports)
  /home/runner/work/pandas/pandas/pandas/io/clipboard/__init__.py:155:18 - error: Import "PyQt4.QtGui" could not be resolved (reportMissingImports)
  /home/runner/work/pandas/pandas/pandas/io/clipboard/__init__.py:537:20 - error: Import "AppKit" could not be resolved (reportMissingImports)
  /home/runner/work/pandas/pandas/pandas/io/clipboard/__init__.py:538:20 - error: Import "Foundation" could not be resolved (reportMissingImports)
  /home/runner/work/pandas/pandas/pandas/io/clipboard/__init__.py:557:20 - error: Import "qtpy" could not be resolved (reportMissingImports)
  /home/runner/work/pandas/pandas/pandas/io/clipboard/__init__.py:564:28 - error: Import "PyQt4" could not be resolved (reportMissingImports)
/home/runner/work/pandas/pandas/pandas/io/excel/_pyxlsb.py
  /home/runner/work/pandas/pandas/pandas/io/excel/_pyxlsb.py:36:14 - error: Import "pyxlsb" could not be resolved (reportMissingImports)
  /home/runner/work/pandas/pandas/pandas/io/excel/_pyxlsb.py:41:14 - error: Import "pyxlsb" could not be resolved (reportMissingImports)

@twoertwein
Copy link
Member Author

Install pyxlsb but don't bother installing all the platform-dependent code for the clipboard.

Should PyQt4 be removed? I don't find it on pip and "PyQt4 and Qt v4 are no longer supported and no new releases will be made."

@twoertwein twoertwein marked this pull request as ready for review September 29, 2021 01:29
@@ -1,6 +1,7 @@
import numpy as np

import pandas._tying as npt
from pandas._typing import npt
Copy link
Member Author

Choose a reason for hiding this comment

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

could replace
from pandas._typing import npt
with
import numpy.typing as npt
in stub files, as I think they will not be executed at run-time - cannot fail even if an old version of numpy is installed.

Copy link
Member

Choose a reason for hiding this comment

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

yep, since we don't need to guard the import at run-time for stub files sgtm.

@twoertwein
Copy link
Member Author

One option could be to enable reportMissingImports but add the following pyright comment to pandas/io/clipboard/__init__.py

# pyright: reportMissingImports=false

xref #43751 (comment)

@twoertwein twoertwein changed the title TYP: temporarily enable reportMissingImports TYP: enable reportMissingImports Sep 29, 2021
@jreback jreback added this to the 1.4 milestone Sep 30, 2021
@jreback jreback added Dependencies Required and optional dependencies Typing type annotations, mypy/pyright type checking labels Sep 30, 2021
@jreback
Copy link
Contributor

jreback commented Sep 30, 2021

looks fine to me. cc @simonjayhawkins

@twoertwein
Copy link
Member Author

Should probably wait until #43799 to not force contributors to install all dependencies.

@jreback
Copy link
Contributor

jreback commented Oct 3, 2021

if you'd rebase (but lgtm).

@simonjayhawkins
Copy link
Member

One option could be to enable reportMissingImports but add the following pyright comment to pandas/io/clipboard/__init__.py

# pyright: reportMissingImports=false

xref #43751 (comment)

since clipboard is vendored, happy to exclude from all pyright checks and limit the use of module level comment syntax for pyright to pandas code

@simonjayhawkins
Copy link
Member

Install pyxlsb but don't bother installing all the platform-dependent code for the clipboard.

in the pip secction of environment.yml we have some typing stubs imports

    - types-python-dateutil
    - types-PyMySQL
    - types-pytz
    - types-setuptools

if the package has stubs we should include it here.

if it is a typed library like numpy, then we already have it in environment.yaml so the missing import only becomes an issue if an older version of numpy is installed.

I'm not sure what is best for untyped optional libraries without stubs packages.

conda solver is already slow for our pandas-dev environment, but otoh happy to add pyxlsb as our dev env should probably have all optional dependencies installed to ensure local testing catches issues. (having some optional dependencies included in environment.yml but not all seems strange)

I assume that as pyxlsb is not a pytyped library and has no stubs, that the imports will resolve to Any. So we gain nothing from a typing perspective other than silencing the pyright warning by adding pyxlsb to environment.yml.

So am also happy not to add.

@twoertwein
Copy link
Member Author

conda solver is already slow for our pandas-dev environment

Fortunately, pyxlsb does not seem to list any dependencies, so it should be quick to resolve :) But enabling the pyright option would also mean that future potentially difficult to resolve packages will be added.

I assume that as pyxlsb is not a pytyped library and has no stubs, that the imports will resolve to Any.

Unfortunately, pyxlsb has no type annotations.

So we gain nothing from a typing perspective other than silencing the pyright warning by adding pyxlsb to environment.yml.

We can catch some typos in pyi files. I was just trying flake8-pyi, it wouldn't have caught these two typos.

Let me know what you think is more important. Happy to remove pyxlsb and not disable MissingImports.

@simonjayhawkins
Copy link
Member

I'm not against enabling the pyright option so that the typos are caught.

We can enable MissingImports without adding to environment.yaml using the module level pyright options syntax to disable MissingImports in just pandas/io/excel/_pyxlsb.py if any objections.

otherwise lgtm.

@jreback jreback merged commit dbfcfb0 into pandas-dev:master Oct 6, 2021
@jreback
Copy link
Contributor

jreback commented Oct 6, 2021

thanks @twoertwein happy being strict here.

gasparitiago pushed a commit to gasparitiago/pandas that referenced this pull request Oct 9, 2021
rhshadrach pushed a commit to rhshadrach/pandas that referenced this pull request Oct 10, 2021
@twoertwein twoertwein deleted the MissingImports branch April 1, 2022 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dependencies Required and optional dependencies Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants