Closed cdce8p closed 11 months ago
Thanks for the PR! Could you run it through the pre-commit hooks and push a commit to fix the lint errors?
pip install pre-commit
pre-commit install
pre-commit run --files zigpy_znp/types/basic.py
You can also make a whitespace-only change and the hook will run automatically upon commit
to correct things.
Patch coverage: 100.00
% and project coverage change: +0.05
:tada:
Comparison is base (
686cb6c
) 98.46% compared to head (fefb3a0
) 98.52%.:exclamation: Current head fefb3a0 differs from pull request most recent head 1f160f3. Consider uploading reports for the commit 1f160f3 to get more accurate results
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
I've started testing Home Assistant with Python 3.12. One common error is
After some investigation I tracked it back to
zigpy-znp
and indeed, running the test suite results in this errorIt can be reproduced by executing just
It is likely related to a change in cpython regarding reassignments of
cls.__new__
andsuper()
, see https://github.com/python/cpython/issues/106917.As it turns out though, the reassignment isn't actually needed anymore. The tests added in 72402da pass for Python 3.10.0+ without it. Likely a side effect of https://github.com/python/cpython/pull/26658.
The complete code I used to validate this change (tested with Python 3.8 - 3.12.0b4)
```py import enum import sys class FixedIntType(int): _signed: bool _size: bool def __new__(cls, *args, **kwargs): if getattr(cls, "_signed", None) is None or getattr(cls, "_size", None) is None: raise TypeError(f"{cls} is abstract and cannot be created") print(f"=> {cls}, {args=}") instance = super().__new__(cls, *args, **kwargs) return instance def __init_subclass__(cls, signed=None, size=None) -> None: super().__init_subclass__() if signed is not None: cls._signed = signed if size is not None: cls._size = size print(cls.__dict__) if sys.version_info < (3, 10): if "__new__" not in cls.__dict__: cls.__new__ = cls.__new__ print(cls.__dict__) class uint_t(FixedIntType, signed=False): pass class uint8_t(uint_t, size=1): pass class uint16_t(uint_t, size=2): pass class CustomInt(uint16_t): def __new__(cls, value: int = 0): instance = super().__new__(cls, value) return instance def with_id(self, value: int): return type(self)(self & 0x00FF | (value & 0xFF) << 8) CustomInt().with_id(4) class enum_uint(uint8_t, enum.Enum): pass class AddrMode(enum_uint): """Address mode.""" NOT_PRESENT = 0x00 Group = 0x01 NWK = 0x02 IEEE = 0x03 Broadcast = 0x0F ```