From fefb3a0fc1755bd90b848ae295cbb0054604a4ee Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 20 Jul 2023 19:37:46 +0200 Subject: [PATCH] Don't reassign cls.__new__ for Python 3.10+ --- zigpy_znp/types/basic.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/zigpy_znp/types/basic.py b/zigpy_znp/types/basic.py index 7580a196..7b033ada 100644 --- a/zigpy_znp/types/basic.py +++ b/zigpy_znp/types/basic.py @@ -1,6 +1,7 @@ from __future__ import annotations import enum +import sys import typing import zigpy.types as zigpy_t @@ -65,10 +66,12 @@ def __init_subclass__(cls, signed=None, size=None, hex_repr=None) -> None: cls.__str__ = super().__str__ cls.__repr__ = super().__repr__ - # XXX: The enum module uses the first class with __new__ in its __dict__ as the - # member type. We have to ensure this is true for every subclass. - if "__new__" not in cls.__dict__: - cls.__new__ = cls.__new__ + if sys.version_info < (3, 10): + # XXX: The enum module uses the first class with __new__ in its __dict__ as the + # member type. We have to ensure this is true for every subclass. + # Fixed with https://github.com/python/cpython/pull/26658 + if "__new__" not in cls.__dict__: + cls.__new__ = cls.__new__ def serialize(self) -> bytes: try: