From b440084730c03499c0d1e74af3f3629aae2d19bd Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 5 Dec 2020 08:51:21 +0100 Subject: [PATCH] Fix compatibility with python3.6+ Signed-off-by: DL6ER --- libnl/misc.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/libnl/misc.py b/libnl/misc.py index 5e970e2..dcfbcb7 100644 --- a/libnl/misc.py +++ b/libnl/misc.py @@ -13,9 +13,22 @@ def _class_factory(base): Returns: New class definition. """ + + # Fixes error on python3.6 and up: + # + # TypeError: __class__ set to + # .ClsPyPy'> + # defining 'ClsPyPy' as + # .ClsPyPy'> + # + # Tis comes from the PEP-487 implementation + # ("PEP-487 -- Simpler customisation of class creation") + # modifying the class construction + base._super = super + class ClsPyPy(base): def __repr__(self): - return repr(base(super(ClsPyPy, self).value)) + return repr(base(base._super(ClsPyPy, self).value)) @classmethod def from_buffer(cls, ba): @@ -31,10 +44,10 @@ def from_buffer(cls, ba): class ClsPy26(base): def __repr__(self): - return repr(base(super(ClsPy26, self).value)) + return repr(base(base._super(ClsPy26, self).value)) def __iter__(self): - return iter(struct.pack(getattr(super(ClsPy26, self), '_type_'), super(ClsPy26, self).value)) + return iter(struct.pack(getattr(base._super(ClsPy26, self), '_type_'), base._super(ClsPy26, self).value)) try: base.from_buffer(bytearray(base()))