Skip to content

Commit 30120a3

Browse files
samuel-gauthierrjarry
authored andcommitted
all: allow to add fields to classes
It can be handy to add custom fields to classes, let's add support for it. As a side-node, this does not degrade performance for access / write for the fields that are in the slots. Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com> Acked-by: Robin Jarry <robin@jarry.cc>
1 parent bfe8a0c commit 30120a3

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

libyang/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# -------------------------------------------------------------------------------------
2323
class Context:
24-
__slots__ = ("cdata",)
24+
__slots__ = ("cdata", "__dict__")
2525

2626
def __init__(
2727
self,

libyang/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class DNode:
193193
Data tree node.
194194
"""
195195

196-
__slots__ = ("context", "cdata", "free_func")
196+
__slots__ = ("context", "cdata", "free_func", "__dict__")
197197

198198
def __init__(self, context: "libyang.Context", cdata):
199199
"""

libyang/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def flatten(node, dic):
8181

8282
# -------------------------------------------------------------------------------------
8383
class SNodeDiff:
84-
pass
84+
__slots__ = ("__dict__",)
8585

8686

8787
# -------------------------------------------------------------------------------------

libyang/schema.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def printer_flags(
4444

4545
# -------------------------------------------------------------------------------------
4646
class Module:
47-
__slots__ = ("context", "cdata")
47+
__slots__ = ("context", "cdata", "__dict__")
4848

4949
def __init__(self, context: "libyang.Context", cdata):
5050
self.context = context
@@ -227,7 +227,7 @@ def parse_data_dict(
227227

228228
# -------------------------------------------------------------------------------------
229229
class Revision:
230-
__slots__ = ("context", "cdata", "module")
230+
__slots__ = ("context", "cdata", "module", "__dict__")
231231

232232
def __init__(self, context: "libyang.Context", cdata, module):
233233
self.context = context
@@ -270,7 +270,7 @@ def __str__(self):
270270

271271
# -------------------------------------------------------------------------------------
272272
class Extension:
273-
__slots__ = ("context", "cdata")
273+
__slots__ = ("context", "cdata", "__dict__")
274274

275275
def __init__(self, context: "libyang.Context", cdata, module_parent: Module = None):
276276
self.context = context
@@ -331,7 +331,7 @@ def module(self) -> Module:
331331

332332
# -------------------------------------------------------------------------------------
333333
class _EnumBit:
334-
__slots__ = ("context", "cdata")
334+
__slots__ = ("context", "cdata", "__dict__")
335335

336336
def __init__(self, context: "libyang.Context", cdata):
337337
self.context = context
@@ -382,7 +382,7 @@ class Bit(_EnumBit):
382382

383383
# -------------------------------------------------------------------------------------
384384
class Type:
385-
__slots__ = ("context", "cdata", "cdata_parsed")
385+
__slots__ = ("context", "cdata", "cdata_parsed", "__dict__")
386386

387387
UNKNOWN = lib.LY_TYPE_UNKNOWN
388388
BINARY = lib.LY_TYPE_BINARY
@@ -609,7 +609,7 @@ def __str__(self):
609609

610610
# -------------------------------------------------------------------------------------
611611
class Feature:
612-
__slots__ = ("context", "cdata")
612+
__slots__ = ("context", "cdata", "__dict__")
613613

614614
def __init__(self, context: "libyang.Context", cdata):
615615
self.context = context
@@ -652,7 +652,7 @@ def __str__(self):
652652

653653
# -------------------------------------------------------------------------------------
654654
class IfFeatureExpr:
655-
__slots__ = ("context", "cdata", "module_features", "compiled")
655+
__slots__ = ("context", "cdata", "module_features", "compiled", "__dict__")
656656

657657
def __init__(self, context: "libyang.Context", cdata, module_features=None):
658658
"""
@@ -875,7 +875,7 @@ def __str__(self):
875875

876876
# -------------------------------------------------------------------------------------
877877
class SNode:
878-
__slots__ = ("context", "cdata", "cdata_parsed")
878+
__slots__ = ("context", "cdata", "cdata_parsed", "__dict__")
879879

880880
CONTAINER = lib.LYS_CONTAINER
881881
LEAF = lib.LYS_LEAF

0 commit comments

Comments
 (0)