Skip to content

Optional dependency networkx is mandatory given type hints #68

@thomas-fred

Description

@thomas-fred

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'?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions