Fix mypy erroring on backport branches by phofl · Pull Request #48240 · pandas-dev/pandas (original) (raw)

The goal of this if condition is to exit early if a non-dev version of pandas is installed: we could simply change it to if not getattr(pd, "__version__", "") to require any installed version. I belief that should work for the CI.

Luckily, stubtest is in the manual stage of pre-commit, so it isn't run by default. The above change would only affect people running pre-commit on the manual stage. If a contributor has non-dev pandasinstalled, stubtest might find discrepancies between the stubs and the non-dev implementation and therefore fail. Personally, I would do the above change and add a comment here
https://github.com/pandas-dev/pandas/blob/main/doc/source/development/contributing_codebase.rst#validating-type-hints

the following might fail if the installed pandas version does not correspond to your local git version

pre-commit run --hook-stage manual --all-files

if the above fails due to stubtest

SKIP=stubtest pre-commit run --hook-stage manual --all-files

(I didn't double check whether that is the correct syntax for skipping a hook in pre-commit)