Skip to content

Commit d1a8f2b

Browse files
authored
Upgrade black (#410)
1 parent 8bfbaae commit d1a8f2b

File tree

10 files changed

+161
-267
lines changed

10 files changed

+161
-267
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
- id: isort
99

1010
- repo: https://github.com/psf/black
11-
rev: 23.7.0
11+
rev: 23.9.1
1212
hooks:
1313
- id: black
1414
args:

tests/b006_b008.py

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

1313
# B006
1414
# Allow immutable literals/calls/comprehensions
15-
def this_is_okay(value=(1, 2, 3)):
16-
...
15+
def this_is_okay(value=(1, 2, 3)): ...
1716

1817

1918
async def and_this_also(value=tuple()):
@@ -50,35 +49,28 @@ def operators_ok_unqualified(
5049
pass
5150

5251

53-
def kwonlyargs_immutable(*, value=()):
54-
...
52+
def kwonlyargs_immutable(*, value=()): ...
5553

5654

5755
# Flag mutable literals/comprehensions
5856

5957

60-
def this_is_wrong(value=[1, 2, 3]):
61-
...
58+
def this_is_wrong(value=[1, 2, 3]): ...
6259

6360

64-
def this_is_also_wrong(value={}):
65-
...
61+
def this_is_also_wrong(value={}): ...
6662

6763

68-
def and_this(value=set()):
69-
...
64+
def and_this(value=set()): ...
7065

7166

72-
def this_too(value=collections.OrderedDict()):
73-
...
67+
def this_too(value=collections.OrderedDict()): ...
7468

7569

76-
async def async_this_too(value=collections.defaultdict()):
77-
...
70+
async def async_this_too(value=collections.defaultdict()): ...
7871

7972

80-
def dont_forget_me(value=collections.deque()):
81-
...
73+
def dont_forget_me(value=collections.deque()): ...
8274

8375

8476
# N.B. we're also flagging the function call in the comprehension
@@ -94,8 +86,7 @@ def set_comprehension_also_not_okay(default={i**2 for i in range(3)}):
9486
pass
9587

9688

97-
def kwonlyargs_mutable(*, value=[]):
98-
...
89+
def kwonlyargs_mutable(*, value=[]): ...
9990

10091

10192
# Recommended approach for mutable defaults
@@ -106,16 +97,14 @@ def do_this_instead(value=None):
10697

10798
# B008
10899
# Flag function calls as default args (including if they are part of a sub-expression)
109-
def in_fact_all_calls_are_wrong(value=time.time()):
110-
...
100+
def in_fact_all_calls_are_wrong(value=time.time()): ...
111101

112102

113103
def f(when=dt.datetime.now() + dt.timedelta(days=7)):
114104
pass
115105

116106

117-
def can_even_catch_lambdas(a=(lambda x: x)()):
118-
...
107+
def can_even_catch_lambdas(a=(lambda x: x)()): ...
119108

120109

121110
# Recommended approach for function calls as default args

tests/b008_extended.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
from fastapi import Query
55

66

7-
def this_is_okay_extended(db=fastapi.Depends(get_db)):
8-
...
7+
def this_is_okay_extended(db=fastapi.Depends(get_db)): ...
98

109

11-
def this_is_okay_extended_second(data: List[str] = fastapi.Query(None)):
12-
...
10+
def this_is_okay_extended_second(data: List[str] = fastapi.Query(None)): ...
1311

1412

15-
def this_is_not_okay_relative_import_not_listed(data: List[str] = Query(None)):
16-
...
13+
def this_is_not_okay_relative_import_not_listed(data: List[str] = Query(None)): ...

tests/b019.py

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,98 +6,77 @@
66
from functools import cache, cached_property, lru_cache
77

88

9-
def some_other_cache():
10-
...
9+
def some_other_cache(): ...
1110

1211

1312
class Foo:
1413
def __init__(self, x):
1514
self.x = x
1615

17-
def compute_method(self, y):
18-
...
16+
def compute_method(self, y): ...
1917

2018
@some_other_cache
21-
def user_cached_method(self, y):
22-
...
19+
def user_cached_method(self, y): ...
2320

2421
@classmethod
2522
@functools.cache
26-
def cached_classmethod(cls, y):
27-
...
23+
def cached_classmethod(cls, y): ...
2824

2925
@classmethod
3026
@cache
31-
def other_cached_classmethod(cls, y):
32-
...
27+
def other_cached_classmethod(cls, y): ...
3328

3429
@classmethod
3530
@functools.lru_cache
36-
def lru_cached_classmethod(cls, y):
37-
...
31+
def lru_cached_classmethod(cls, y): ...
3832

3933
@classmethod
4034
@lru_cache
41-
def other_lru_cached_classmethod(cls, y):
42-
...
35+
def other_lru_cached_classmethod(cls, y): ...
4336

4437
@staticmethod
4538
@functools.cache
46-
def cached_staticmethod(y):
47-
...
39+
def cached_staticmethod(y): ...
4840

4941
@staticmethod
5042
@cache
51-
def other_cached_staticmethod(y):
52-
...
43+
def other_cached_staticmethod(y): ...
5344

5445
@staticmethod
5546
@functools.lru_cache
56-
def lru_cached_staticmethod(y):
57-
...
47+
def lru_cached_staticmethod(y): ...
5848

5949
@staticmethod
6050
@lru_cache
61-
def other_lru_cached_staticmethod(y):
62-
...
51+
def other_lru_cached_staticmethod(y): ...
6352

6453
@functools.cached_property
65-
def some_cached_property(self):
66-
...
54+
def some_cached_property(self): ...
6755

6856
@cached_property
69-
def some_other_cached_property(self):
70-
...
57+
def some_other_cached_property(self): ...
7158

7259
# Remaining methods should emit B019
7360
@functools.cache
74-
def cached_method(self, y):
75-
...
61+
def cached_method(self, y): ...
7662

7763
@cache
78-
def another_cached_method(self, y):
79-
...
64+
def another_cached_method(self, y): ...
8065

8166
@functools.cache()
82-
def called_cached_method(self, y):
83-
...
67+
def called_cached_method(self, y): ...
8468

8569
@cache()
86-
def another_called_cached_method(self, y):
87-
...
70+
def another_called_cached_method(self, y): ...
8871

8972
@functools.lru_cache
90-
def lru_cached_method(self, y):
91-
...
73+
def lru_cached_method(self, y): ...
9274

9375
@lru_cache
94-
def another_lru_cached_method(self, y):
95-
...
76+
def another_lru_cached_method(self, y): ...
9677

9778
@functools.lru_cache()
98-
def called_lru_cached_method(self, y):
99-
...
79+
def called_lru_cached_method(self, y): ...
10080

10181
@lru_cache()
102-
def another_called_lru_cached_method(self, y):
103-
...
82+
def another_called_lru_cached_method(self, y): ...

tests/b027.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@ def empty_5(self): # error
3232
...
3333

3434
@abstractmethod
35-
def abstract_1(self):
36-
...
35+
def abstract_1(self): ...
3736

3837
@abstractmethod
3938
def abstract_2(self):
4039
pass
4140

4241
@abc.abstractmethod
43-
def abstract_3(self):
44-
...
42+
def abstract_3(self): ...
4543

4644
def body_1(self):
4745
print("foo")
@@ -69,21 +67,16 @@ def empty_2(self): # safe
6967

7068
class AstractClass(ABC):
7169
@overload
72-
def empty_1(self, foo: str):
73-
...
70+
def empty_1(self, foo: str): ...
7471

7572
@typing.overload
76-
def empty_1(self, foo: int):
77-
...
73+
def empty_1(self, foo: int): ...
7874

7975
@t.overload
80-
def empty_1(self, foo: list):
81-
...
76+
def empty_1(self, foo: list): ...
8277

8378
@anything.overload
84-
def empty_1(self, foo: float):
85-
...
79+
def empty_1(self, foo: float): ...
8680

8781
@abstractmethod
88-
def empty_1(self, foo: Union[str, int, list, float]):
89-
...
82+
def empty_1(self, foo: Union[str, int, list, float]): ...

tests/b902.py

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,79 @@
1-
def not_a_method(arg1):
2-
...
1+
def not_a_method(arg1): ...
32

43

54
class NoWarnings:
65
def __init__(self):
7-
def not_a_method_either(arg1):
8-
...
6+
def not_a_method_either(arg1): ...
97

10-
def __new__(cls, *args, **kwargs):
11-
...
8+
def __new__(cls, *args, **kwargs): ...
129

13-
def method(self, arg1, *, yeah):
14-
...
10+
def method(self, arg1, *, yeah): ...
1511

16-
async def async_method(self, arg1, *, yeah):
17-
...
12+
async def async_method(self, arg1, *, yeah): ...
1813

1914
@classmethod
20-
def someclassmethod(cls, arg1, with_default=None):
21-
...
15+
def someclassmethod(cls, arg1, with_default=None): ...
2216

2317
@staticmethod
24-
def not_a_problem(arg1):
25-
...
18+
def not_a_problem(arg1): ...
2619

2720

2821
class Warnings:
29-
def __init__(i_am_special):
30-
...
22+
def __init__(i_am_special): ...
3123

32-
def almost_a_class_method(cls, arg1):
33-
...
24+
def almost_a_class_method(cls, arg1): ...
3425

35-
def almost_a_static_method():
36-
...
26+
def almost_a_static_method(): ...
3727

3828
@classmethod
39-
def wat(self, i_like_confusing_people):
40-
...
29+
def wat(self, i_like_confusing_people): ...
4130

4231
def i_am_strange(*args, **kwargs):
4332
self = args[0]
4433

45-
def defaults_anyone(self=None):
46-
...
34+
def defaults_anyone(self=None): ...
4735

48-
def invalid_kwargs_only(**kwargs):
49-
...
36+
def invalid_kwargs_only(**kwargs): ...
5037

51-
def invalid_keyword_only(*, self):
52-
...
38+
def invalid_keyword_only(*, self): ...
5339

54-
async def async_invalid_keyword_only(*, self):
55-
...
40+
async def async_invalid_keyword_only(*, self): ...
5641

5742

5843
class Meta(type):
59-
def __init__(cls, name, bases, d):
60-
...
44+
def __init__(cls, name, bases, d): ...
6145

6246
@classmethod
6347
def __prepare__(metacls, name, bases):
6448
return {}
6549

6650

6751
class OtherMeta(type):
68-
def __init__(self, name, bases, d):
69-
...
52+
def __init__(self, name, bases, d): ...
7053

7154
@classmethod
7255
def __prepare__(cls, name, bases):
7356
return {}
7457

7558
@classmethod
76-
def first_arg_mcs_allowed(mcs, value):
77-
...
59+
def first_arg_mcs_allowed(mcs, value): ...
7860

7961

8062
def type_factory():
8163
return object
8264

8365

8466
class CrazyBases(Warnings, type_factory(), metaclass=type):
85-
def __init__(self):
86-
...
67+
def __init__(self): ...
8768

8869

8970
class RuntimeError("This is not a base"):
90-
def __init__(self):
91-
...
71+
def __init__(self): ...
9272

9373

9474
class ImplicitClassMethods:
95-
def __new__(cls, *args, **kwargs):
96-
...
75+
def __new__(cls, *args, **kwargs): ...
9776

98-
def __init_subclass__(cls, *args, **kwargs):
99-
...
77+
def __init_subclass__(cls, *args, **kwargs): ...
10078

101-
def __class_getitem__(cls, key):
102-
...
79+
def __class_getitem__(cls, key): ...

0 commit comments

Comments
 (0)