Skip to content

Commit

Permalink
Merge pull request #140 from puddly/puddly/pyproject-and-pyupgrade
Browse files Browse the repository at this point in the history
Add pyupgrade and autoflake8
  • Loading branch information
puddly authored Mar 2, 2022
2 parents b095b6f + 8d2b349 commit 0cacf7a
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ 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.pyupgrade]
py37plus = true

[tool.tox]
legacy_tox_ini = """
[tox]
Expand Down
23 changes: 0 additions & 23 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/application/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion zigpy_znp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
2 changes: 0 additions & 2 deletions zigpy_znp/types/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
14 changes: 7 additions & 7 deletions zigpy_znp/types/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand All @@ -125,15 +125,15 @@ 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
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:
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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

Expand All @@ -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.
"""
Expand Down
2 changes: 0 additions & 2 deletions zigpy_znp/types/named.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions zigpy_znp/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0cacf7a

Please sign in to comment.