Skip to content

Commit 0cacf7a

Browse files
authored
Merge pull request #140 from puddly/puddly/pyproject-and-pyupgrade
Add pyupgrade and autoflake8
2 parents b095b6f + 8d2b349 commit 0cacf7a

File tree

10 files changed

+38
-39
lines changed

10 files changed

+38
-39
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ jobs:
267267
--timeout=20 \
268268
--durations=10 \
269269
--cov zigpy_znp \
270+
--cov-config pyproject.toml \
270271
-o console_output_style=count \
271272
-p no:sugar \
272273
tests

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@ repos:
3434
- id: mypy
3535
additional_dependencies:
3636
- zigpy==0.43.0
37+
38+
- repo: https://github.com/asottile/pyupgrade
39+
rev: v2.31.0
40+
hooks:
41+
- id: pyupgrade
42+
43+
- repo: https://github.com/fsouza/autoflake8
44+
rev: v0.3.1
45+
hooks:
46+
- id: autoflake8

pyproject.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ max-line-length = 88
3737
# D202 No blank lines allowed after function docstring
3838
ignore = "W503,E203,D202"
3939

40+
[tool.mypy]
41+
check_untyped_defs = true
42+
show_error_codes = true
43+
show_error_context = true
44+
disable_error_code = [
45+
"attr-defined",
46+
"assignment",
47+
"arg-type",
48+
"union-attr",
49+
"var-annotated",
50+
"name-defined",
51+
]
52+
53+
[tool.coverage.run]
54+
source = ["zigpy_znp"]
55+
56+
[tool.pyupgrade]
57+
py37plus = true
58+
4059
[tool.tox]
4160
legacy_tox_ini = """
4261
[tox]

setup.cfg

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,3 @@ testing =
3636
pytest-cov
3737
coveralls
3838
asynctest; python_version < "3.8.0"
39-
40-
[coverage:run]
41-
source = zigpy_znp
42-
43-
[flake8]
44-
max-line-length = 88
45-
46-
[mypy]
47-
ignore_missing_imports = True
48-
install_types = True
49-
non_interactive = True
50-
check_untyped_defs = True
51-
show_error_codes = True
52-
show_error_context = True
53-
disable_error_code =
54-
attr-defined,
55-
arg-type,
56-
type-var,
57-
var-annotated,
58-
assignment,
59-
call-overload,
60-
name-defined,
61-
union-attr

tests/application/test_connect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async def test_leak_detection(make_znp_server, mocker):
2727
znp_server = make_znp_server(server_cls=FormedLaunchpadCC26X2R1)
2828

2929
def count_connected():
30-
return sum([t._is_connected for t in znp_server._transports])
30+
return sum(t._is_connected for t in znp_server._transports)
3131

3232
# Opening and closing one connection will keep the count at zero
3333
assert count_connected() == 0

zigpy_znp/api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,6 @@ def connection_made(self) -> None:
591591
"""
592592
Called by the UART object when a connection has been made.
593593
"""
594-
pass
595594

596595
def connection_lost(self, exc) -> None:
597596
"""

zigpy_znp/types/basic.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ class TrailingBytes(Bytes):
2929
Bytes must occur at the very end of a parameter list for easy parsing.
3030
"""
3131

32-
pass
33-
3432

3533
def serialize_list(objects) -> Bytes:
3634
return Bytes(b"".join([o.serialize() for o in objects]))

zigpy_znp/types/commands.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class CommandHeader(t.uint16_t):
9393

9494
def __new__(
9595
cls, value: int = 0x0000, *, id=None, subsystem=None, type=None
96-
) -> "CommandHeader":
96+
) -> CommandHeader:
9797
instance = super().__new__(cls, value)
9898

9999
if id is not None:
@@ -116,7 +116,7 @@ def id(self) -> t.uint8_t:
116116
"""Return CommandHeader id."""
117117
return t.uint8_t(self >> 8)
118118

119-
def with_id(self, value: int) -> "CommandHeader":
119+
def with_id(self, value: int) -> CommandHeader:
120120
"""command ID setter."""
121121
return type(self)(self & 0x00FF | (value & 0xFF) << 8)
122122

@@ -125,15 +125,15 @@ def subsystem(self) -> Subsystem:
125125
"""Return subsystem of the command."""
126126
return Subsystem(self.cmd0 & 0x1F)
127127

128-
def with_subsystem(self, value: Subsystem) -> "CommandHeader":
128+
def with_subsystem(self, value: Subsystem) -> CommandHeader:
129129
return type(self)(self & 0xFFE0 | value & 0x1F)
130130

131131
@property
132132
def type(self) -> CommandType:
133133
"""Return command type."""
134134
return CommandType(self.cmd0 >> 5)
135135

136-
def with_type(self, value) -> "CommandHeader":
136+
def with_type(self, value) -> CommandHeader:
137137
return type(self)(self & 0xFF1F | (value & 0x07) << 5)
138138

139139
def __str__(self) -> str:
@@ -399,7 +399,7 @@ def to_frame(self, *, align=False):
399399
return GeneralFrame(self.header, b"".join(chunks))
400400

401401
@classmethod
402-
def from_frame(cls, frame, *, align=False) -> "CommandBase":
402+
def from_frame(cls, frame, *, align=False) -> CommandBase:
403403
if frame.header != cls.header:
404404
raise ValueError(
405405
f"Wrong frame header in {cls}: {cls.header} != {frame.header}"
@@ -435,7 +435,7 @@ def from_frame(cls, frame, *, align=False) -> "CommandBase":
435435

436436
return cls(**params)
437437

438-
def matches(self, other: "CommandBase") -> bool:
438+
def matches(self, other: CommandBase) -> bool:
439439
if type(self) is not type(other):
440440
return False
441441

@@ -455,7 +455,7 @@ def matches(self, other: "CommandBase") -> bool:
455455

456456
return True
457457

458-
def replace(self, **kwargs) -> "CommandBase":
458+
def replace(self, **kwargs) -> CommandBase:
459459
"""
460460
Returns a copy of the current command with replaced parameters.
461461
"""

zigpy_znp/types/named.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ def __repr__(self) -> str:
9696
class GroupId(basic.uint16_t, hex_repr=True):
9797
"""Group ID class"""
9898

99-
pass
100-
10199

102100
class ScanType(basic.enum_uint8):
103101
EnergyDetect = 0x00

zigpy_znp/zigbee/application.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ async def permit_ncp(self, time_s: int) -> None:
536536
"""
537537

538538
# Z-Stack does not need any special code to do this
539-
pass
540539

541540
async def permit_with_key(self, node: t.EUI64, code: bytes, time_s=60):
542541
"""
@@ -641,8 +640,6 @@ def on_intentionally_unhandled_message(self, msg: t.CommandBase) -> None:
641640
reduce unnecessary logging messages, they are given an explicit callback.
642641
"""
643642

644-
pass
645-
646643
async def on_zdo_message(self, msg: c.ZDO.MsgCbIncoming.Callback) -> None:
647644
"""
648645
Global callback for all ZDO messages.

0 commit comments

Comments
 (0)