From 967e862ab16358df61b535007cf07c349d8860d8 Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Mon, 6 Feb 2023 14:52:46 -0500 Subject: [PATCH] NetworkXGraphEdgeDescriptor: Use __set_name__. Still need the __init__ use to handle a single case of overriding the name. Signed-off-by: Chris PeBenito --- setools/descriptors.py | 11 +++++++---- setools/dta.py | 14 +++++++------- setools/infoflow.py | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/setools/descriptors.py b/setools/descriptors.py index 7aca848..2d8edf5 100644 --- a/setools/descriptors.py +++ b/setools/descriptors.py @@ -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: diff --git a/setools/dta.py b/setools/dta.py index 1448820..3f87677 100644 --- a/setools/dta.py +++ b/setools/dta.py @@ -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 diff --git a/setools/infoflow.py b/setools/infoflow.py index 2afb47e..cc45a34 100644 --- a/setools/infoflow.py +++ b/setools/infoflow.py @@ -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.