Skip to content
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

Undefined type annotations in _helpers.py #73

Closed
adonath opened this issue Dec 14, 2023 · 5 comments
Closed

Undefined type annotations in _helpers.py #73

adonath opened this issue Dec 14, 2023 · 5 comments

Comments

@adonath
Copy link
Contributor

adonath commented Dec 14, 2023

My VScode with ruff extension showed that the Device and Array annotations in common/_helpers.py are undefined:

image

And from a quick look I think this is true. Maybe adopt ruff as a default linter / .pre-commit hook?

@adonath
Copy link
Contributor Author

adonath commented Dec 14, 2023

Here is a full list of further issues marked by ruff:

array_api_compat/__init__.py:22:1: F403 `from .common import *` used; unable to detect undefined names
array_api_compat/common/__init__.py:1:1: F403 `from ._helpers import *` used; unable to detect undefined names
array_api_compat/common/_aliases.py:9:58: F401 [*] `typing.List` imported but unused
array_api_compat/common/_aliases.py:283:33: F821 Undefined name `np`
array_api_compat/common/_helpers.py:147:16: F821 Undefined name `Array`
array_api_compat/common/_helpers.py:147:31: F821 Undefined name `Device`
array_api_compat/common/_helpers.py:213:9: F821 Undefined name `Array`
array_api_compat/common/_helpers.py:213:26: F821 Undefined name `Device`
array_api_compat/common/_helpers.py:213:50: F821 Undefined name `Optional`
array_api_compat/common/_helpers.py:213:59: F821 Undefined name `Union`
array_api_compat/common/_helpers.py:213:70: F821 Undefined name `Any`
array_api_compat/common/_helpers.py:214:7: F821 Undefined name `Array`
array_api_compat/common/_linalg.py:5:43: F401 [*] `typing.Sequence` imported but unused
array_api_compat/cupy/__init__.py:1:1: F403 `from cupy import *` used; unable to detect undefined names
array_api_compat/cupy/__init__.py:4:18: F401 [*] `cupy.abs` imported but unused
array_api_compat/cupy/__init__.py:4:23: F401 [*] `cupy.max` imported but unused
array_api_compat/cupy/__init__.py:4:28: F401 [*] `cupy.min` imported but unused
array_api_compat/cupy/__init__.py:4:33: F401 [*] `cupy.round` imported but unused
array_api_compat/cupy/__init__.py:7:1: F403 `from ._aliases import *` used; unable to detect undefined names
array_api_compat/cupy/__init__.py:12:1: E402 Module level import not at top of file
array_api_compat/cupy/__init__.py:12:21: F401 [*] `.linalg.matrix_transpose` imported but unused
array_api_compat/cupy/__init__.py:12:39: F401 [*] `.linalg.vecdot` imported but unused
array_api_compat/cupy/__init__.py:14:1: E402 Module level import not at top of file
array_api_compat/cupy/__init__.py:14:1: F403 `from ..common._helpers import *` used; unable to detect undefined names
array_api_compat/cupy/_aliases.py:13:1: E402 Module level import not at top of file
array_api_compat/cupy/linalg.py:1:1: F403 `from cupy.linalg import *` used; unable to detect undefined names
array_api_compat/cupy/linalg.py:11:1: E402 Module level import not at top of file
array_api_compat/cupy/linalg.py:12:1: E402 Module level import not at top of file
array_api_compat/cupy/linalg.py:13:1: E402 Module level import not at top of file
array_api_compat/cupy/linalg.py:13:24: F401 [*] `._aliases.matmul` imported but unused
array_api_compat/cupy/linalg.py:13:32: F401 [*] `._aliases.matrix_transpose` imported but unused
array_api_compat/cupy/linalg.py:13:50: F401 [*] `._aliases.tensordot` imported but unused
array_api_compat/cupy/linalg.py:13:61: F401 [*] `._aliases.vecdot` imported but unused
array_api_compat/cupy/linalg.py:15:1: E402 Module level import not at top of file
array_api_compat/numpy/__init__.py:1:1: F403 `from numpy import *` used; unable to detect undefined names
array_api_compat/numpy/__init__.py:4:19: F401 [*] `numpy.abs` imported but unused
array_api_compat/numpy/__init__.py:4:24: F401 [*] `numpy.max` imported but unused
array_api_compat/numpy/__init__.py:4:29: F401 [*] `numpy.min` imported but unused
array_api_compat/numpy/__init__.py:4:34: F401 [*] `numpy.round` imported but unused
array_api_compat/numpy/__init__.py:7:1: F403 `from ._aliases import *` used; unable to detect undefined names
array_api_compat/numpy/__init__.py:18:1: E402 Module level import not at top of file
array_api_compat/numpy/__init__.py:18:21: F401 [*] `.linalg.matrix_transpose` imported but unused
array_api_compat/numpy/__init__.py:18:39: F401 [*] `.linalg.vecdot` imported but unused
array_api_compat/numpy/__init__.py:20:1: E402 Module level import not at top of file
array_api_compat/numpy/__init__.py:20:1: F403 `from ..common._helpers import *` used; unable to detect undefined names
array_api_compat/numpy/_aliases.py:13:1: E402 Module level import not at top of file
array_api_compat/numpy/linalg.py:1:1: F403 `from numpy.linalg import *` used; unable to detect undefined names
array_api_compat/numpy/linalg.py:6:24: F401 [*] `._aliases.matmul` imported but unused
array_api_compat/numpy/linalg.py:6:32: F401 [*] `._aliases.matrix_transpose` imported but unused
array_api_compat/numpy/linalg.py:6:50: F401 [*] `._aliases.tensordot` imported but unused
array_api_compat/numpy/linalg.py:6:61: F401 [*] `._aliases.vecdot` imported but unused
array_api_compat/torch/__init__.py:1:1: F403 `from torch import *` used; unable to detect undefined names
array_api_compat/torch/__init__.py:15:1: E402 Module level import not at top of file
array_api_compat/torch/__init__.py:15:1: F403 `from ._aliases import *` used; unable to detect undefined names
array_api_compat/torch/__init__.py:20:1: E402 Module level import not at top of file
array_api_compat/torch/__init__.py:20:1: F403 `from ..common._helpers import *` used; unable to detect undefined names
array_api_compat/torch/linalg.py:8:1: F403 `from torch.linalg import *` used; unable to detect undefined names
array_api_compat/torch/linalg.py:16:1: E402 Module level import not at top of file
array_api_compat/torch/linalg.py:17:1: E402 Module level import not at top of file

@adonath
Copy link
Contributor Author

adonath commented Dec 18, 2023

I'd be happy to open a PR for this. I could either:

  • Define a CI that runs ruff as a check
  • Add a pre-commit hook running ruff
  • Something else?

@asmeurer
Copy link
Member

All the "imported but unused" and "import *" warnings are intentional, because we are manually exporting/rexporting names to the compat namespaces. We can add some linting, but we will need a lot of ignores, maybe even ignoring those checks entirely, at least for certain files.

The typing things should be fixed. I haven't checked if the typing stuff here works at all, so there's probably a lot more work that should be done there. The types in the signatures are copied from the spec, but I don't know if the aliases like "Device" actually work or not. No one has complained about it yet, though, so either it's fine or people are just ignoring the types for this library.

At any rate, feel free to open a PR and we can discuss this more.

@adonath
Copy link
Contributor Author

adonath commented Feb 20, 2024

Resolved via #82.

@adonath adonath closed this as completed Feb 20, 2024
@NeilGirdhar
Copy link
Contributor

@asmeurer If you instead add your imported names to __all__, you won't get the linter errors.

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

No branches or pull requests

3 participants