Skip to content

Commit d694b7e

Browse files
committed
one step closer to flake8
1 parent c845425 commit d694b7e

46 files changed

Lines changed: 377 additions & 189 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,11 @@ If you would like to contribute to the development, here are a few things that y
4545
- Make sure that you stick to the style guide;
4646
refinery code should pass [flake8], with some tests disabled.
4747

48-
You do not have to worry about the following [flake8] tests:
49-
50-
- The following tests are disabled to allow command line argument annotations to work:
51-
- `F821` (undefined name)
52-
- `F722` (syntax error in forward annotation)
53-
- `E704` (multiple statements on one line (def))
54-
- `E701` (multiple statements on one line (colon))
55-
- `E128` (continuation line is under-indented for a visual indentation)
56-
- The following tests are disabled because the maintainer doesn't like them:
48+
You do not have to worry about the following [flake8] tests, they are disabled because the maintainer doesn't like them:
5749
- `W503` (line break occurred before a binary operator)
5850
- `E203` (colons should not have any space before them)
59-
51+
- `E128` (continuation line is under-indented for a visual indentation)
52+
- `E261` (at least two spaces before inline comment)
6053

6154

6255
[b64]: refinery/units/encoding/b64.py

refinery/lib/argformats.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,13 @@ class DelayedArgumentDispatch:
446446
register additional handlers.
447447
"""
448448
class Wrapper:
449-
def can_handle(self, *a): return self.ego.can_handle(*a)
450-
def terminates(self, *a): return self.ego.terminates(*a)
449+
def can_handle(self, *a):
450+
return self.ego.can_handle(*a)
451451

452-
def __init__(self, ego, arg):
452+
def terminates(self, *a):
453+
return self.ego.terminates(*a)
454+
455+
def __init__(self, ego: DelayedArgumentDispatch, arg):
453456
self.ego = ego
454457
self.arg = arg
455458

@@ -1137,7 +1140,7 @@ def itob(self, integers: Iterable[int], size=None) -> buf:
11371140
if not size:
11381141
def byte_length(n: int):
11391142
width, overflow = divmod(n.bit_length(), 8)
1140-
if overflow: width += 1
1143+
width += bool(overflow)
11411144
return width
11421145
if not isinstance(integers, list):
11431146
integers = list(integers)

refinery/lib/colors.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010

1111
if TYPE_CHECKING:
1212
@overload
13-
def colored_text_truncate(string: str, end: int) -> str: ...
13+
def colored_text_truncate(string: str, end: int) -> str:
14+
...
15+
1416
@overload
15-
def colored_text_truncate(string: buf, end: int) -> bytes: ...
17+
def colored_text_truncate(string: buf, end: int) -> bytes:
18+
...
19+
1620
@overload
17-
def colored_text_bleach(string: str) -> str: ...
21+
def colored_text_bleach(string: str) -> str:
22+
...
23+
1824
@overload
19-
def colored_text_bleach(string: buf) -> bytes: ...
25+
def colored_text_bleach(string: buf) -> bytes:
26+
...
2027

2128

2229
def colored_text_bleach(string: str | buf):

refinery/lib/inline.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ def iterspread_method(self):
112112

113113
function_name = None
114114

115-
def as_arg(name: str): return F'_arg_{name}'
116-
def as_var(name: str): return F'_var_{name}'
117-
def as_tmp(name: str): return F'_tmp_{name}'
115+
def as_arg(name: str):
116+
return F'_arg_{name}'
117+
118+
def as_var(name: str):
119+
return F'_var_{name}'
120+
121+
def as_tmp(name: str):
122+
return F'_tmp_{name}'
118123

119124
def apply_node_transformation(cls: type[NodeTransformer]):
120125
nonlocal code

refinery/lib/java.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def __init__(self, _: StructReader, pool: list, tag: JvConstType):
9797

9898
class JvStructWithName(_HasPoolAndTag):
9999
name: str = Index(str)
100-
def __repr__(self): return self.name
100+
101+
def __repr__(self):
102+
return self.name
101103

102104

103105
class JvNameAndType(JvStructWithName):
@@ -403,7 +405,8 @@ class opc(IntEnum):
403405
impdep1 = 0xfe # noqa
404406
impdep2 = 0xff # noqa
405407

406-
def __repr__(self) -> str: return self.name
408+
def __repr__(self) -> str:
409+
return self.name
407410

408411

409412
class JvBaseType(IntEnum):
@@ -416,7 +419,8 @@ class JvBaseType(IntEnum):
416419
INT = 0xA # noqa
417420
LONG = 0xB # noqa
418421

419-
def __repr__(self) -> str: return self.name
422+
def __repr__(self) -> str:
423+
return self.name
420424

421425

422426
class JvTypePath:
@@ -580,7 +584,7 @@ def __init__(self, reader: StructReader, pool: list):
580584

581585
class JvClassFile(Struct):
582586

583-
TYPEHANDLER: dict[JvConstType, Struct] = {
587+
TYPEHANDLER: dict[JvConstType, type[Struct]] = {
584588
JvConstType.Class : JvString,
585589
JvConstType.String : JvString,
586590
JvConstType.Field : JvClassProperty,

refinery/lib/meta.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ class CustomStringRepresentation(abc.ABC):
151151
"""
152152

153153
@abc.abstractmethod
154-
def __str__(self): ...
154+
def __str__(self) -> str:
155+
...
155156

156157
@abc.abstractmethod
157-
def __repr__(self): ...
158+
def __repr__(self) -> str:
159+
...
158160

159161

160162
_INDEX = 'index'
@@ -698,7 +700,8 @@ def format(
698700

699701
if used is None:
700702
class dummy:
701-
def add(self, _): pass
703+
def add(self, _):
704+
pass
702705
used = dummy()
703706

704707
if args is None:

refinery/lib/mscrypto.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212

1313

1414
class _ENUM(enum.IntEnum):
15-
def __str__(self): return self.name
16-
def __repr__(self): return self.name
15+
def __str__(self):
16+
return self.name
17+
18+
def __repr__(self):
19+
return self.name
1720

1821

1922
class TYPES(_ENUM):
@@ -93,15 +96,17 @@ def __init__(self, reader: StructReader):
9396

9497

9598
class PLAINTEXTKEYBLOB(Struct):
96-
def __bytes__(self): return bytes(self.data)
99+
def __bytes__(self):
100+
return bytes(self.data)
97101

98102
def __init__(self, reader: StructReader):
99103
self.size = reader.u32()
100104
self.data = reader.read(self.size)
101105

102106

103107
class SIMPLEBLOB(Struct):
104-
def __bytes__(self): return bytes(self.data)
108+
def __bytes__(self):
109+
return bytes(self.data)
105110

106111
def __init__(self, reader: StructReader):
107112
self.magic = reader.read(4)

refinery/lib/ripemd128.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ def ripemd128(message):
4949
0xF, 0x5, 0x8, 0xB, 0xE, 0xE, 0x6, 0xE, 0x6, 0x9, 0xC, 0x9, 0xC, 0x5, 0xF, 0x8,
5050
]
5151

52-
def F0(x, y, z): return (x ^ y ^ z)
53-
def F1(x, y, z): return (x & y) | (z & ~x)
54-
def F2(x, y, z): return (x | (0xffffffff & ~y)) ^ z
55-
def F3(x, y, z): return (x & z) | (y & ~z)
52+
def F0(x, y, z):
53+
return (x ^ y ^ z)
54+
55+
def F1(x, y, z):
56+
return (x & y) | (z & ~x)
57+
58+
def F2(x, y, z):
59+
return (x | (0xffffffff & ~y)) ^ z
60+
61+
def F3(x, y, z):
62+
return (x & z) | (y & ~z)
5663

5764
F = [F0, F1, F2, F3]
5865

refinery/lib/suffixtree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def fixlinks(self):
6868

6969
def __repr__(self) -> str:
7070
label = bytes(self.label).decode('utf8', errors='backslashreplace')
71-
if label: label = F': {label}'
71+
label = label and F': {label}'
7272
return F'<{self.__class__.__name__}{label}>'
7373

7474
def __iter__(self) -> Iterable[Node]:

refinery/lib/tools.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,14 @@ def terminalfit(text: str, delta: int = 0, width: int = 0, parsep: str = '\n\n',
9696
width = width or get_terminal_size()
9797
width = width - delta
9898

99-
def isol(t): return re.match(R'^\(\d+\)|\d+[.:;]', t)
100-
def isul(t): return t.startswith('-') or t.startswith('*')
101-
def issp(t): return t.startswith(' ')
99+
def isol(t):
100+
return re.match(R'^\(\d+\)|\d+[.:;]', t)
101+
102+
def isul(t):
103+
return t.startswith('-') or t.startswith('*')
104+
105+
def issp(t):
106+
return t.startswith(' ')
102107

103108
text = text.replace('\r', '')
104109

0 commit comments

Comments
 (0)