Skip to content

Commit

Permalink
Upgrade black (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja authored Sep 13, 2023
1 parent 8bfbaae commit d1a8f2b
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 267 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black
args:
Expand Down
33 changes: 11 additions & 22 deletions tests/b006_b008.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

# B006
# Allow immutable literals/calls/comprehensions
def this_is_okay(value=(1, 2, 3)):
...
def this_is_okay(value=(1, 2, 3)): ...


async def and_this_also(value=tuple()):
Expand Down Expand Up @@ -50,35 +49,28 @@ def operators_ok_unqualified(
pass


def kwonlyargs_immutable(*, value=()):
...
def kwonlyargs_immutable(*, value=()): ...


# Flag mutable literals/comprehensions


def this_is_wrong(value=[1, 2, 3]):
...
def this_is_wrong(value=[1, 2, 3]): ...


def this_is_also_wrong(value={}):
...
def this_is_also_wrong(value={}): ...


def and_this(value=set()):
...
def and_this(value=set()): ...


def this_too(value=collections.OrderedDict()):
...
def this_too(value=collections.OrderedDict()): ...


async def async_this_too(value=collections.defaultdict()):
...
async def async_this_too(value=collections.defaultdict()): ...


def dont_forget_me(value=collections.deque()):
...
def dont_forget_me(value=collections.deque()): ...


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


def kwonlyargs_mutable(*, value=[]):
...
def kwonlyargs_mutable(*, value=[]): ...


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

# B008
# Flag function calls as default args (including if they are part of a sub-expression)
def in_fact_all_calls_are_wrong(value=time.time()):
...
def in_fact_all_calls_are_wrong(value=time.time()): ...


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


def can_even_catch_lambdas(a=(lambda x: x)()):
...
def can_even_catch_lambdas(a=(lambda x: x)()): ...


# Recommended approach for function calls as default args
Expand Down
9 changes: 3 additions & 6 deletions tests/b008_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
from fastapi import Query


def this_is_okay_extended(db=fastapi.Depends(get_db)):
...
def this_is_okay_extended(db=fastapi.Depends(get_db)): ...


def this_is_okay_extended_second(data: List[str] = fastapi.Query(None)):
...
def this_is_okay_extended_second(data: List[str] = fastapi.Query(None)): ...


def this_is_not_okay_relative_import_not_listed(data: List[str] = Query(None)):
...
def this_is_not_okay_relative_import_not_listed(data: List[str] = Query(None)): ...
63 changes: 21 additions & 42 deletions tests/b019.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,98 +6,77 @@
from functools import cache, cached_property, lru_cache


def some_other_cache():
...
def some_other_cache(): ...


class Foo:
def __init__(self, x):
self.x = x

def compute_method(self, y):
...
def compute_method(self, y): ...

@some_other_cache
def user_cached_method(self, y):
...
def user_cached_method(self, y): ...

@classmethod
@functools.cache
def cached_classmethod(cls, y):
...
def cached_classmethod(cls, y): ...

@classmethod
@cache
def other_cached_classmethod(cls, y):
...
def other_cached_classmethod(cls, y): ...

@classmethod
@functools.lru_cache
def lru_cached_classmethod(cls, y):
...
def lru_cached_classmethod(cls, y): ...

@classmethod
@lru_cache
def other_lru_cached_classmethod(cls, y):
...
def other_lru_cached_classmethod(cls, y): ...

@staticmethod
@functools.cache
def cached_staticmethod(y):
...
def cached_staticmethod(y): ...

@staticmethod
@cache
def other_cached_staticmethod(y):
...
def other_cached_staticmethod(y): ...

@staticmethod
@functools.lru_cache
def lru_cached_staticmethod(y):
...
def lru_cached_staticmethod(y): ...

@staticmethod
@lru_cache
def other_lru_cached_staticmethod(y):
...
def other_lru_cached_staticmethod(y): ...

@functools.cached_property
def some_cached_property(self):
...
def some_cached_property(self): ...

@cached_property
def some_other_cached_property(self):
...
def some_other_cached_property(self): ...

# Remaining methods should emit B019
@functools.cache
def cached_method(self, y):
...
def cached_method(self, y): ...

@cache
def another_cached_method(self, y):
...
def another_cached_method(self, y): ...

@functools.cache()
def called_cached_method(self, y):
...
def called_cached_method(self, y): ...

@cache()
def another_called_cached_method(self, y):
...
def another_called_cached_method(self, y): ...

@functools.lru_cache
def lru_cached_method(self, y):
...
def lru_cached_method(self, y): ...

@lru_cache
def another_lru_cached_method(self, y):
...
def another_lru_cached_method(self, y): ...

@functools.lru_cache()
def called_lru_cached_method(self, y):
...
def called_lru_cached_method(self, y): ...

@lru_cache()
def another_called_lru_cached_method(self, y):
...
def another_called_lru_cached_method(self, y): ...
21 changes: 7 additions & 14 deletions tests/b027.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ def empty_5(self): # error
...

@abstractmethod
def abstract_1(self):
...
def abstract_1(self): ...

@abstractmethod
def abstract_2(self):
pass

@abc.abstractmethod
def abstract_3(self):
...
def abstract_3(self): ...

def body_1(self):
print("foo")
Expand Down Expand Up @@ -69,21 +67,16 @@ def empty_2(self): # safe

class AstractClass(ABC):
@overload
def empty_1(self, foo: str):
...
def empty_1(self, foo: str): ...

@typing.overload
def empty_1(self, foo: int):
...
def empty_1(self, foo: int): ...

@t.overload
def empty_1(self, foo: list):
...
def empty_1(self, foo: list): ...

@anything.overload
def empty_1(self, foo: float):
...
def empty_1(self, foo: float): ...

@abstractmethod
def empty_1(self, foo: Union[str, int, list, float]):
...
def empty_1(self, foo: Union[str, int, list, float]): ...
69 changes: 23 additions & 46 deletions tests/b902.py
Original file line number Diff line number Diff line change
@@ -1,102 +1,79 @@
def not_a_method(arg1):
...
def not_a_method(arg1): ...


class NoWarnings:
def __init__(self):
def not_a_method_either(arg1):
...
def not_a_method_either(arg1): ...

def __new__(cls, *args, **kwargs):
...
def __new__(cls, *args, **kwargs): ...

def method(self, arg1, *, yeah):
...
def method(self, arg1, *, yeah): ...

async def async_method(self, arg1, *, yeah):
...
async def async_method(self, arg1, *, yeah): ...

@classmethod
def someclassmethod(cls, arg1, with_default=None):
...
def someclassmethod(cls, arg1, with_default=None): ...

@staticmethod
def not_a_problem(arg1):
...
def not_a_problem(arg1): ...


class Warnings:
def __init__(i_am_special):
...
def __init__(i_am_special): ...

def almost_a_class_method(cls, arg1):
...
def almost_a_class_method(cls, arg1): ...

def almost_a_static_method():
...
def almost_a_static_method(): ...

@classmethod
def wat(self, i_like_confusing_people):
...
def wat(self, i_like_confusing_people): ...

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

def defaults_anyone(self=None):
...
def defaults_anyone(self=None): ...

def invalid_kwargs_only(**kwargs):
...
def invalid_kwargs_only(**kwargs): ...

def invalid_keyword_only(*, self):
...
def invalid_keyword_only(*, self): ...

async def async_invalid_keyword_only(*, self):
...
async def async_invalid_keyword_only(*, self): ...


class Meta(type):
def __init__(cls, name, bases, d):
...
def __init__(cls, name, bases, d): ...

@classmethod
def __prepare__(metacls, name, bases):
return {}


class OtherMeta(type):
def __init__(self, name, bases, d):
...
def __init__(self, name, bases, d): ...

@classmethod
def __prepare__(cls, name, bases):
return {}

@classmethod
def first_arg_mcs_allowed(mcs, value):
...
def first_arg_mcs_allowed(mcs, value): ...


def type_factory():
return object


class CrazyBases(Warnings, type_factory(), metaclass=type):
def __init__(self):
...
def __init__(self): ...


class RuntimeError("This is not a base"):
def __init__(self):
...
def __init__(self): ...


class ImplicitClassMethods:
def __new__(cls, *args, **kwargs):
...
def __new__(cls, *args, **kwargs): ...

def __init_subclass__(cls, *args, **kwargs):
...
def __init_subclass__(cls, *args, **kwargs): ...

def __class_getitem__(cls, key):
...
def __class_getitem__(cls, key): ...
Loading

0 comments on commit d1a8f2b

Please sign in to comment.