diff --git a/.flake8 b/.flake8 index 0bb586b18e..37f5883f00 100644 --- a/.flake8 +++ b/.flake8 @@ -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* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f7e548518..cb7882d38f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/linter-requirements.txt b/linter-requirements.txt index 53edc6477f..f29b068609 100644 --- a/linter-requirements.txt +++ b/linter-requirements.txt @@ -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 diff --git a/sentry_sdk/_compat.py b/sentry_sdk/_compat.py index 49a55392a7..40ae40126b 100644 --- a/sentry_sdk/_compat.py +++ b/sentry_sdk/_compat.py @@ -15,7 +15,7 @@ PY2 = sys.version_info[0] == 2 if PY2: - import urlparse # noqa + import urlparse text_type = unicode # noqa @@ -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): diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py index f4a44e4500..cec914aca1 100644 --- a/sentry_sdk/api.py +++ b/sentry_sdk/api.py @@ -108,7 +108,7 @@ def add_breadcrumb( @overload -def configure_scope(): # noqa: F811 +def configure_scope(): # type: () -> ContextManager[Scope] pass @@ -130,7 +130,7 @@ def configure_scope( # noqa: F811 @overload -def push_scope(): # noqa: F811 +def push_scope(): # type: () -> ContextManager[Scope] pass @@ -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) diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index 33870e2df0..3d4a28d526 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -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] @@ -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] @@ -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]] """ diff --git a/sentry_sdk/integrations/serverless.py b/sentry_sdk/integrations/serverless.py index c46f8cee31..c22fbfd37f 100644 --- a/sentry_sdk/integrations/serverless.py +++ b/sentry_sdk/integrations/serverless.py @@ -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 diff --git a/sentry_sdk/integrations/starlette.py b/sentry_sdk/integrations/starlette.py index 0342a64344..2d23250fa0 100644 --- a/sentry_sdk/integrations/starlette.py +++ b/sentry_sdk/integrations/starlette.py @@ -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 diff --git a/sentry_sdk/profiler.py b/sentry_sdk/profiler.py index 1116d59017..d774ff8a01 100644 --- a/sentry_sdk/profiler.py +++ b/sentry_sdk/profiler.py @@ -25,7 +25,6 @@ import sentry_sdk from sentry_sdk._compat import PY2 - from sentry_sdk._types import MYPY if MYPY: diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index ccac6e37e3..3279b3f2bd 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -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: diff --git a/tests/conftest.py b/tests/conftest.py index 7479a3e213..a239ccc1fe 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index 3375ee76ad..7e49a285c3 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -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( diff --git a/tests/integrations/aws_lambda/test_aws.py b/tests/integrations/aws_lambda/test_aws.py index c6fb54b94f..458f55bf1a 100644 --- a/tests/integrations/aws_lambda/test_aws.py +++ b/tests/integrations/aws_lambda/test_aws.py @@ -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 diff --git a/tests/integrations/django/test_basic.py b/tests/integrations/django/test_basic.py index 329fc04f9c..89365ab6ba 100644 --- a/tests/integrations/django/test_basic.py +++ b/tests/integrations/django/test_basic.py @@ -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) diff --git a/tests/test_envelope.py b/tests/test_envelope.py index 582fe6236f..b6a3ddf8be 100644 --- a/tests/test_envelope.py +++ b/tests/test_envelope.py @@ -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] @@ -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]