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

Optional dependency networkx is mandatory given type hints #68

Open
thomas-fred opened this issue Sep 16, 2024 · 0 comments
Open

Optional dependency networkx is mandatory given type hints #68

thomas-fred opened this issue Sep 16, 2024 · 0 comments

Comments

@thomas-fred
Copy link
Collaborator

thomas-fred commented Sep 16, 2024

snkit has networkx as an optional dependency. If you don't have networkx, but try to use functions that require it, snkit tries to raise an import error. However, there are type hints in function signatures in network.py that use networkx and therefore when importing snkit without networkx, snkit fails on load with the following:

Python 3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:45:18) [GCC 12.3.0] on linux
>>> import snkit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/fred/micromamba/envs/jamaica-infrastructure/lib/python3.10/site-packages/snkit/__init__.py", line 7, in <module>
    from snkit.network import Network
  File "/home/fred/micromamba/envs/jamaica-infrastructure/lib/python3.10/site-packages/snkit/network.py", line 964, in <module>
    ) -> Union[nx.Graph, nx.DiGraph]:
NameError: name 'nx' is not defined. Did you mean: 'np'?
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

1 participant