NetworkXGraphEdgeDescriptor: Use __set_name__.

Still need the __init__ use to handle a single case of overriding the name.

Signed-off-by: Chris PeBenito <chpebeni@linux.microsoft.com>
This commit is contained in:
Chris PeBenito 2023-02-06 14:52:46 -05:00
parent 2d1de939ba
commit 967e862ab1
3 changed files with 15 additions and 12 deletions

View File

@ -189,8 +189,8 @@ class NetworkXGraphEdgeDescriptor(ABC):
"""
Descriptor abstract base class for NetworkX graph edge attributes.
Parameter:
name The edge property name
Keyword Parameter:
name Override the graph edge property name.
Instance class attribute use (obj parameter):
G The NetworkX graph
@ -198,8 +198,11 @@ class NetworkXGraphEdgeDescriptor(ABC):
target The edge's target node
"""
def __init__(self, propname: str) -> None:
self.name = propname
def __init__(self, propname: Optional[str] = None) -> None:
self.override_name = propname
def __set_name__(self, owner, name):
self.name = self.override_name if self.override_name else name
def __get__(self, obj, objtype=None):
if obj is None:

View File

@ -595,13 +595,13 @@ class Edge:
The default is False.
"""
transition = EdgeAttrList('transition')
setexec = EdgeAttrList('setexec')
dyntransition = EdgeAttrList('dyntransition')
setcurrent = EdgeAttrList('setcurrent')
entrypoint = EdgeAttrDict('entrypoint')
execute = EdgeAttrDict('execute')
type_transition = EdgeAttrDict('type_transition')
transition = EdgeAttrList()
setexec = EdgeAttrList()
dyntransition = EdgeAttrList()
setcurrent = EdgeAttrList()
entrypoint = EdgeAttrDict()
execute = EdgeAttrDict()
type_transition = EdgeAttrDict()
def __init__(self, graph, source: Type, target: Type, create: bool = False) -> None:
self.G = graph

View File

@ -405,7 +405,7 @@ class InfoFlowStep:
The default is False.
"""
rules = EdgeAttrList('rules')
rules = EdgeAttrList()
# use capacity to store the info flow weight so
# we can use network flow algorithms naturally.