Typing Hints for Inheritance #2115
-
|
Hello, I am trying to use the networkx-types package to annotate the specific nodes I am using on my graph. Specifically, I want to inherit from the nx.DiGraph class with type hints, which should look something like this: However, this fails with |
Beta Was this translation helpful? Give feedback.
Answered by
Daraan
Nov 18, 2025
Replies: 1 comment 2 replies
-
|
This can happen is there is a stub package for type-hints, but the actual runtime implementation is non-generic. You can work around this by defining your child class like this: from typing import TYPE_CHECKING
class MyGraph(nx.DiGraph[NodeType] if TYPE_CHECKING else nx.DiGraph):
... |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
patschmidt2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can happen is there is a stub package for type-hints, but the actual runtime implementation is non-generic. You can work around this by defining your child class like this: