Describe the bug, including details regarding any error messages, version, and platform.
Consider the following snippet:
docker run \
--rm \
-it python:3.13 \
bash
pip install 'pyarrow>=24.0' 'mypy'
cat > test.py <<EOF
import pyarrow as pa
import pyarrow.compute as pa_compute
def all_ones(arr) -> bool:
return pa_compute.all(pa_compute.equal(arr, 1))
if __name__ == "__main__":
X = pa.array([1, 1, 1])
print(f"all ones?: {all_ones(X)}")
EOF
This is totally plausible pyarrow code and works as expected.
$ python ./test.py
all ones?: True
But mypy complains about it referencing things that don't exist in pyarrow
$ mypy --version
mypy 1.20.2 (compiled: yes)
$ mypy ./test.py
test.py:5: error: Module has no attribute "all" [attr-defined]
test.py:5: error: Module has no attribute "equal" [attr-defined]
Found 2 errors in 1 file (checked 1 source file)
Notes
Similar errors are not surfaced by type checkers like mypy on pyarrow<24, so I strongly suspect this is related to something new in the 24.0 release. Possibly the introduction of type-checking infrastructure (a py.typed file and .pyi stubs), around #48618
Maybe the .pyi stub file(s) are incomplete? At https://mypy.readthedocs.io/en/stable/stubs.html#creating-a-stub, I see:
If a directory contains both a .py and a .pyi file for the same module, the .pyi file takes precedence.
Or maybe mypy does not handle well situations where things are added to globals at import time like this?
Thanks for your time and consideration.
Component(s)
Python
Describe the bug, including details regarding any error messages, version, and platform.
Consider the following snippet:
This is totally plausible
pyarrowcode and works as expected.But
mypycomplains about it referencing things that don't exist inpyarrowNotes
Similar errors are not surfaced by type checkers like
mypyonpyarrow<24, so I strongly suspect this is related to something new in the 24.0 release. Possibly the introduction of type-checking infrastructure (apy.typedfile and.pyistubs), around #48618Maybe the
.pyistub file(s) are incomplete? At https://mypy.readthedocs.io/en/stable/stubs.html#creating-a-stub, I see:Or maybe
mypydoes not handle well situations where things are added toglobalsat import time like this?arrow/python/pyarrow/compute.py
Line 343 in acd8e44
Thanks for your time and consideration.
Component(s)
Python