From 585960240d1ffc400d84ce835adb2a82abac6dec Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Tue, 1 Mar 2022 15:42:55 -0500 Subject: [PATCH 1/3] Move MyPy config into `pyproject.toml` --- .github/workflows/ci.yml | 1 + pyproject.toml | 16 ++++++++++++++++ setup.cfg | 23 ----------------------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 458dff6b..f5bd1281 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -267,6 +267,7 @@ jobs: --timeout=20 \ --durations=10 \ --cov zigpy_znp \ + --cov-config pyproject.toml \ -o console_output_style=count \ -p no:sugar \ tests diff --git a/pyproject.toml b/pyproject.toml index 2767c404..d5883499 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,22 @@ max-line-length = 88 # D202 No blank lines allowed after function docstring ignore = "W503,E203,D202" +[tool.mypy] +check_untyped_defs = true +show_error_codes = true +show_error_context = true +disable_error_code = [ + "attr-defined", + "assignment", + "arg-type", + "union-attr", + "var-annotated", + "name-defined", +] + +[tool.coverage.run] +source = "zigpy_znp" + [tool.tox] legacy_tox_ini = """ [tox] diff --git a/setup.cfg b/setup.cfg index 869d1b46..7b850549 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,26 +36,3 @@ testing = pytest-cov coveralls asynctest; python_version < "3.8.0" - -[coverage:run] -source = zigpy_znp - -[flake8] -max-line-length = 88 - -[mypy] -ignore_missing_imports = True -install_types = True -non_interactive = True -check_untyped_defs = True -show_error_codes = True -show_error_context = True -disable_error_code = - attr-defined, - arg-type, - type-var, - var-annotated, - assignment, - call-overload, - name-defined, - union-attr From bb369f733fbda752afa4a66f6e4d9ac65dc9f5b4 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Tue, 1 Mar 2022 15:46:38 -0500 Subject: [PATCH 2/3] Add pyupgrade and autoflake8 --- .pre-commit-config.yaml | 10 ++++++++++ pyproject.toml | 3 +++ tests/application/test_connect.py | 2 +- zigpy_znp/api.py | 1 - zigpy_znp/types/basic.py | 2 -- zigpy_znp/types/commands.py | 14 +++++++------- zigpy_znp/types/named.py | 2 -- zigpy_znp/zigbee/application.py | 3 --- 8 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 08b04bd4..de5e9e19 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,3 +34,13 @@ repos: - id: mypy additional_dependencies: - zigpy==0.43.0 + + - repo: https://github.com/asottile/pyupgrade + rev: v2.31.0 + hooks: + - id: pyupgrade + + - repo: https://github.com/fsouza/autoflake8 + rev: v0.3.1 + hooks: + - id: autoflake8 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index d5883499..b29f55cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,6 +53,9 @@ disable_error_code = [ [tool.coverage.run] source = "zigpy_znp" +[tool.pyupgrade] +py37plus = true + [tool.tox] legacy_tox_ini = """ [tox] diff --git a/tests/application/test_connect.py b/tests/application/test_connect.py index 2a0fb022..6568dad4 100644 --- a/tests/application/test_connect.py +++ b/tests/application/test_connect.py @@ -27,7 +27,7 @@ async def test_leak_detection(make_znp_server, mocker): znp_server = make_znp_server(server_cls=FormedLaunchpadCC26X2R1) def count_connected(): - return sum([t._is_connected for t in znp_server._transports]) + return sum(t._is_connected for t in znp_server._transports) # Opening and closing one connection will keep the count at zero assert count_connected() == 0 diff --git a/zigpy_znp/api.py b/zigpy_znp/api.py index 30c510c2..ecc71e60 100644 --- a/zigpy_znp/api.py +++ b/zigpy_znp/api.py @@ -591,7 +591,6 @@ def connection_made(self) -> None: """ Called by the UART object when a connection has been made. """ - pass def connection_lost(self, exc) -> None: """ diff --git a/zigpy_znp/types/basic.py b/zigpy_znp/types/basic.py index c65bbbba..112469bf 100644 --- a/zigpy_znp/types/basic.py +++ b/zigpy_znp/types/basic.py @@ -29,8 +29,6 @@ class TrailingBytes(Bytes): Bytes must occur at the very end of a parameter list for easy parsing. """ - pass - def serialize_list(objects) -> Bytes: return Bytes(b"".join([o.serialize() for o in objects])) diff --git a/zigpy_znp/types/commands.py b/zigpy_znp/types/commands.py index 4a1fc7e1..80ef4621 100644 --- a/zigpy_znp/types/commands.py +++ b/zigpy_znp/types/commands.py @@ -93,7 +93,7 @@ class CommandHeader(t.uint16_t): def __new__( cls, value: int = 0x0000, *, id=None, subsystem=None, type=None - ) -> "CommandHeader": + ) -> CommandHeader: instance = super().__new__(cls, value) if id is not None: @@ -116,7 +116,7 @@ def id(self) -> t.uint8_t: """Return CommandHeader id.""" return t.uint8_t(self >> 8) - def with_id(self, value: int) -> "CommandHeader": + def with_id(self, value: int) -> CommandHeader: """command ID setter.""" return type(self)(self & 0x00FF | (value & 0xFF) << 8) @@ -125,7 +125,7 @@ def subsystem(self) -> Subsystem: """Return subsystem of the command.""" return Subsystem(self.cmd0 & 0x1F) - def with_subsystem(self, value: Subsystem) -> "CommandHeader": + def with_subsystem(self, value: Subsystem) -> CommandHeader: return type(self)(self & 0xFFE0 | value & 0x1F) @property @@ -133,7 +133,7 @@ def type(self) -> CommandType: """Return command type.""" return CommandType(self.cmd0 >> 5) - def with_type(self, value) -> "CommandHeader": + def with_type(self, value) -> CommandHeader: return type(self)(self & 0xFF1F | (value & 0x07) << 5) def __str__(self) -> str: @@ -399,7 +399,7 @@ def to_frame(self, *, align=False): return GeneralFrame(self.header, b"".join(chunks)) @classmethod - def from_frame(cls, frame, *, align=False) -> "CommandBase": + def from_frame(cls, frame, *, align=False) -> CommandBase: if frame.header != cls.header: raise ValueError( f"Wrong frame header in {cls}: {cls.header} != {frame.header}" @@ -435,7 +435,7 @@ def from_frame(cls, frame, *, align=False) -> "CommandBase": return cls(**params) - def matches(self, other: "CommandBase") -> bool: + def matches(self, other: CommandBase) -> bool: if type(self) is not type(other): return False @@ -455,7 +455,7 @@ def matches(self, other: "CommandBase") -> bool: return True - def replace(self, **kwargs) -> "CommandBase": + def replace(self, **kwargs) -> CommandBase: """ Returns a copy of the current command with replaced parameters. """ diff --git a/zigpy_znp/types/named.py b/zigpy_znp/types/named.py index 004fa0be..f492b109 100644 --- a/zigpy_znp/types/named.py +++ b/zigpy_znp/types/named.py @@ -96,8 +96,6 @@ def __repr__(self) -> str: class GroupId(basic.uint16_t, hex_repr=True): """Group ID class""" - pass - class ScanType(basic.enum_uint8): EnergyDetect = 0x00 diff --git a/zigpy_znp/zigbee/application.py b/zigpy_znp/zigbee/application.py index 8697dabc..453330e4 100644 --- a/zigpy_znp/zigbee/application.py +++ b/zigpy_znp/zigbee/application.py @@ -536,7 +536,6 @@ async def permit_ncp(self, time_s: int) -> None: """ # Z-Stack does not need any special code to do this - pass async def permit_with_key(self, node: t.EUI64, code: bytes, time_s=60): """ @@ -641,8 +640,6 @@ def on_intentionally_unhandled_message(self, msg: t.CommandBase) -> None: reduce unnecessary logging messages, they are given an explicit callback. """ - pass - async def on_zdo_message(self, msg: c.ZDO.MsgCbIncoming.Callback) -> None: """ Global callback for all ZDO messages. From 8d2b34923851c1969a95f258f2c62263ac5224ad Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Wed, 2 Mar 2022 14:17:15 -0500 Subject: [PATCH 3/3] Make coverage source a list --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b29f55cf..7d5f9579 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ disable_error_code = [ ] [tool.coverage.run] -source = "zigpy_znp" +source = ["zigpy_znp"] [tool.pyupgrade] py37plus = true