Skip to content

Commit

Permalink
ref: upgrade linters to flake8 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile-sentry committed Sep 19, 2022
1 parent b36d84a commit 74e0932
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 54 deletions.
31 changes: 16 additions & 15 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
[flake8]
ignore =
E203, // Handled by black (Whitespace before ':' -- handled by black)
E266, // Handled by black (Too many leading '#' for block comment)
E501, // Handled by black (Line too long)
W503, // Handled by black (Line break occured before a binary operator)
E402, // Sometimes not possible due to execution order (Module level import is not at top of file)
E731, // I don't care (Do not assign a lambda expression, use a def)
B950, // Handled by black (Line too long by flake8-bugbear)
B011, // I don't care (Do not call assert False)
B014, // does not apply to Python 2 (redundant exception types by flake8-bugbear)
N812, // I don't care (Lowercase imported as non-lowercase by pep8-naming)
N804 // is a worse version of and conflicts with B902 (first argument of a classmethod should be named cls)
max-line-length = 80
select = N,B,C,E,F,W,T4,B9
exclude=checkouts,lol*,.tox
extend-ignore =
# Handled by black (Whitespace before ':' -- handled by black)
E203,
# Handled by black (Line too long)
E501,
# Sometimes not possible due to execution order (Module level import is not at top of file)
E402,
# I don't care (Do not assign a lambda expression, use a def)
E731,
# does not apply to Python 2 (redundant exception types by flake8-bugbear)
B014,
# I don't care (Lowercase imported as non-lowercase by pep8-naming)
N812,
# is a worse version of and conflicts with B902 (first argument of a classmethod should be named cls)
N804,
extend-exclude=checkouts,lol*
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ repos:
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8

Expand Down
7 changes: 3 additions & 4 deletions linter-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
black==22.3.0
flake8==3.9.2
flake8-import-order==0.18.1
flake8==5.0.4
mypy==0.961
types-certifi
types-redis
types-setuptools
flake8-bugbear==21.4.3
pep8-naming==0.13.0
flake8-bugbear==22.9.11
pep8-naming==0.13.2
pre-commit # local linting
4 changes: 2 additions & 2 deletions sentry_sdk/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
PY2 = sys.version_info[0] == 2

if PY2:
import urlparse # noqa
import urlparse

text_type = unicode # noqa

Expand All @@ -39,7 +39,7 @@ def implements_str(cls):
text_type = str
string_types = (text_type,) # type: Tuple[type]
number_types = (int, float) # type: Tuple[type, type]
int_types = (int,) # noqa
int_types = (int,)
iteritems = lambda x: x.items()

def implements_str(x):
Expand Down
14 changes: 7 additions & 7 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def add_breadcrumb(


@overload
def configure_scope(): # noqa: F811
def configure_scope():
# type: () -> ContextManager[Scope]
pass

Expand All @@ -130,7 +130,7 @@ def configure_scope( # noqa: F811


@overload
def push_scope(): # noqa: F811
def push_scope():
# type: () -> ContextManager[Scope]
pass

Expand All @@ -151,31 +151,31 @@ def push_scope( # noqa: F811
return Hub.current.push_scope(callback)


@scopemethod # noqa
@scopemethod
def set_tag(key, value):
# type: (str, Any) -> None
return Hub.current.scope.set_tag(key, value)


@scopemethod # noqa
@scopemethod
def set_context(key, value):
# type: (str, Dict[str, Any]) -> None
return Hub.current.scope.set_context(key, value)


@scopemethod # noqa
@scopemethod
def set_extra(key, value):
# type: (str, Any) -> None
return Hub.current.scope.set_extra(key, value)


@scopemethod # noqa
@scopemethod
def set_user(value):
# type: (Optional[Dict[str, Any]]) -> None
return Hub.current.scope.set_user(value)


@scopemethod # noqa
@scopemethod
def set_level(value):
# type: (str) -> None
return Hub.current.scope.set_level(value)
Expand Down
6 changes: 3 additions & 3 deletions sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def start_transaction(
return transaction

@overload
def push_scope( # noqa: F811
def push_scope(
self, callback=None # type: Optional[None]
):
# type: (...) -> ContextManager[Scope]
Expand Down Expand Up @@ -595,7 +595,7 @@ def pop_scope_unsafe(self):
return rv

@overload
def configure_scope( # noqa: F811
def configure_scope(
self, callback=None # type: Optional[None]
):
# type: (...) -> ContextManager[Scope]
Expand All @@ -610,7 +610,7 @@ def configure_scope( # noqa: F811

def configure_scope( # noqa
self, callback=None # type: Optional[Callable[[Scope], None]]
): # noqa
):
# type: (...) -> Optional[ContextManager[Scope]]

"""
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/serverless.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def overload(x):


@overload
def serverless_function(f, flush=True): # noqa: F811
def serverless_function(f, flush=True):
# type: (F, bool) -> F
pass

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

try:
# Optional dependency of Starlette to parse form data.
import multipart # type: ignore # noqa: F401
import multipart # type: ignore
except ImportError:
multipart = None

Expand Down
1 change: 0 additions & 1 deletion sentry_sdk/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import sentry_sdk
from sentry_sdk._compat import PY2

from sentry_sdk._types import MYPY

if MYPY:
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def _get_contextvars():
# `aiocontextvars` is absolutely required for functional
# contextvars on Python 3.6.
try:
from aiocontextvars import ContextVar # noqa
from aiocontextvars import ContextVar

return True, ContextVar
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def __init__(self, substring):
try:
# the `unicode` type only exists in python 2, so if this blows up,
# we must be in py3 and have the `bytes` type
self.valid_types = (str, unicode) # noqa
self.valid_types = (str, unicode)
except NameError:
self.valid_types = (str, bytes)

Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/aiohttp/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ async def test_traces_sampler_gets_request_object_in_sampling_context(
sentry_init,
aiohttp_client,
DictionaryContaining, # noqa:N803
ObjectDescribedBy, # noqa:N803
ObjectDescribedBy,
):
traces_sampler = mock.Mock()
sentry_init(
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/aws_lambda/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ def test_handler(event, context):
def test_traces_sampler_gets_correct_values_in_sampling_context(
run_lambda_function,
DictionaryContaining, # noqa:N803
ObjectDescribedBy, # noqa:N803
StringContaining, # noqa:N803
ObjectDescribedBy,
StringContaining,
):
# TODO: This whole thing is a little hacky, specifically around the need to
# get `conftest.py` code into the AWS runtime, which is why there's both
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/django/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def test_rest_framework_basic(
elif ct == "application/x-www-form-urlencoded":
client.post(reverse(route), data=body)
else:
assert False
raise AssertionError("unreachable")

(error,) = exceptions
assert isinstance(error, ZeroDivisionError)
Expand Down
24 changes: 12 additions & 12 deletions tests/test_envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ def test_envelope_with_sized_items():
"""
envelope_raw = (
b'{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"}\n'
+ b'{"type":"type1","length":4 }\n1234\n'
+ b'{"type":"type2","length":4 }\nabcd\n'
+ b'{"type":"type3","length":0}\n\n'
+ b'{"type":"type4","length":4 }\nab12\n'
b'{"type":"type1","length":4 }\n1234\n'
b'{"type":"type2","length":4 }\nabcd\n'
b'{"type":"type3","length":0}\n\n'
b'{"type":"type4","length":4 }\nab12\n'
)
envelope_raw_eof_terminated = envelope_raw[:-1]

for envelope_raw in (envelope_raw, envelope_raw_eof_terminated):
actual = Envelope.deserialize(envelope_raw)
for envelope in (envelope_raw, envelope_raw_eof_terminated):
actual = Envelope.deserialize(envelope)

items = [item for item in actual]

Expand Down Expand Up @@ -177,15 +177,15 @@ def test_envelope_with_implicitly_sized_items():
"""
envelope_raw = (
b'{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"}\n'
+ b'{"type":"type1"}\n1234\n'
+ b'{"type":"type2"}\nabcd\n'
+ b'{"type":"type3"}\n\n'
+ b'{"type":"type4"}\nab12\n'
b'{"type":"type1"}\n1234\n'
b'{"type":"type2"}\nabcd\n'
b'{"type":"type3"}\n\n'
b'{"type":"type4"}\nab12\n'
)
envelope_raw_eof_terminated = envelope_raw[:-1]

for envelope_raw in (envelope_raw, envelope_raw_eof_terminated):
actual = Envelope.deserialize(envelope_raw)
for envelope in (envelope_raw, envelope_raw_eof_terminated):
actual = Envelope.deserialize(envelope)
assert actual.headers["event_id"] == "9ec79c33ec9942ab8353589fcb2e04dc"

items = [item for item in actual]
Expand Down

0 comments on commit 74e0932

Please sign in to comment.