Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.11 compatibility #195

Merged
merged 4 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, "3.10"]
python-version: [3.8, 3.9, "3.10", "3.11"]
steps:
- name: Check out code from GitHub
uses: actions/checkout@v2
Expand Down Expand Up @@ -224,7 +224,7 @@ jobs:
needs: prepare-base
strategy:
matrix:
python-version: [3.8, 3.9, "3.10"]
python-version: [3.8, 3.9, "3.10", "3.11"]
name: >-
Run tests Python ${{ matrix.python-version }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ license = GPL-3.0

[options]
packages = find:
python_requires = >=3.7
python_requires = >=3.8
install_requires =
zigpy>=0.51.0
zigpy>=0.52.0
async_timeout
voluptuous
coloredlogs
Expand Down
1 change: 1 addition & 0 deletions zigpy_znp/commands/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class NodeRelation(t.enum_uint8):
CHILD_FFD_RX_IDLE = 4
NEIGHBOR = 5
OTHER = 6
UNKNOWN_8 = 8
NOTUSED = 0xFF


Expand Down
2 changes: 1 addition & 1 deletion zigpy_znp/tools/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class ClosableFileType(argparse.FileType):
def __call__(self, string):
f = super().__call__(string)

if f not in (sys.stdin, sys.stdout):
if f not in (sys.stdin, sys.stdout, sys.stdin.buffer, sys.stdout.buffer):
return f

return UnclosableFile(f)
Expand Down
42 changes: 10 additions & 32 deletions zigpy_znp/types/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import enum
import typing

import zigpy.types as zigpy_t

from zigpy_znp.types.cstruct import CStruct


Expand Down Expand Up @@ -264,30 +266,6 @@ def deserialize(cls, data: bytes, *, align=False) -> tuple[CompleteList, bytes]:
return r, data


def enum_flag_factory(int_type: FixedIntType) -> enum.Flag:
"""
Mixins are broken by Python 3.8.6 so we must dynamically create the enum with the
appropriate methods but with only one non-Enum parent class.
"""

class _NewEnum(int_type, enum.Flag): # type:ignore[misc,valid-type]
# Rebind classmethods to our own class
_missing_ = classmethod(enum.IntFlag._missing_.__func__)
_create_pseudo_member_ = classmethod(
enum.IntFlag._create_pseudo_member_.__func__
)

__or__ = enum.IntFlag.__or__
__and__ = enum.IntFlag.__and__
__xor__ = enum.IntFlag.__xor__
__ror__ = enum.IntFlag.__ror__
__rand__ = enum.IntFlag.__rand__
__rxor__ = enum.IntFlag.__rxor__
__invert__ = enum.IntFlag.__invert__

return _NewEnum # type:ignore[return-value]


class enum_uint8(uint8_t, enum.Enum):
pass

Expand Down Expand Up @@ -320,33 +298,33 @@ class enum_uint64(uint64_t, enum.Enum):
pass


class enum_flag_uint8(enum_flag_factory(uint8_t)): # type:ignore[misc]
class enum_flag_uint8(zigpy_t.bitmap_factory(uint8_t)): # type:ignore[misc]
pass


class enum_flag_uint16(enum_flag_factory(uint16_t)): # type:ignore[misc]
class enum_flag_uint16(zigpy_t.bitmap_factory(uint16_t)): # type:ignore[misc]
pass


class enum_flag_uint24(enum_flag_factory(uint24_t)): # type:ignore[misc]
class enum_flag_uint24(zigpy_t.bitmap_factory(uint24_t)): # type:ignore[misc]
pass


class enum_flag_uint32(enum_flag_factory(uint32_t)): # type:ignore[misc]
class enum_flag_uint32(zigpy_t.bitmap_factory(uint32_t)): # type:ignore[misc]
pass


class enum_flag_uint40(enum_flag_factory(uint40_t)): # type:ignore[misc]
class enum_flag_uint40(zigpy_t.bitmap_factory(uint40_t)): # type:ignore[misc]
pass


class enum_flag_uint48(enum_flag_factory(uint48_t)): # type:ignore[misc]
class enum_flag_uint48(zigpy_t.bitmap_factory(uint48_t)): # type:ignore[misc]
pass


class enum_flag_uint56(enum_flag_factory(uint56_t)): # type:ignore[misc]
class enum_flag_uint56(zigpy_t.bitmap_factory(uint56_t)): # type:ignore[misc]
pass


class enum_flag_uint64(enum_flag_factory(uint64_t)): # type:ignore[misc]
class enum_flag_uint64(zigpy_t.bitmap_factory(uint64_t)): # type:ignore[misc]
pass