diff --git a/linter-requirements.txt b/linter-requirements.txt index 8c7dd7d6e5..744904fbc2 100644 --- a/linter-requirements.txt +++ b/linter-requirements.txt @@ -1,4 +1,4 @@ -black==21.7b0 +black==22.3.0 flake8==3.9.2 flake8-import-order==0.18.1 mypy==0.782 diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 1720993c1a..efc8799c00 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -451,7 +451,6 @@ class get_options(ClientConstructor, Dict[str, Any]): # noqa: N801 class Client(ClientConstructor, _Client): pass - else: # Alias `get_options` for actual usage. Go through the lambda indirection # to throw PyCharm off of the weakly typed signature (it would otherwise diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index addca57417..22f3ff42fd 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -120,7 +120,6 @@ def _init(*args, **kwargs): class init(ClientConstructor, ContextManager[Any]): # noqa: N801 pass - else: # Alias `init` for actual usage. Go through the lambda indirection to throw # PyCharm off of the weakly typed signature (it would otherwise discover diff --git a/sentry_sdk/integrations/_wsgi_common.py b/sentry_sdk/integrations/_wsgi_common.py index f4cc7672e9..4f253acc35 100644 --- a/sentry_sdk/integrations/_wsgi_common.py +++ b/sentry_sdk/integrations/_wsgi_common.py @@ -39,8 +39,8 @@ def request_body_within_bounds(client, content_length): bodies = client.options["request_bodies"] return not ( bodies == "never" - or (bodies == "small" and content_length > 10 ** 3) - or (bodies == "medium" and content_length > 10 ** 4) + or (bodies == "small" and content_length > 10**3) + or (bodies == "medium" and content_length > 10**4) ) diff --git a/sentry_sdk/integrations/django/__init__.py b/sentry_sdk/integrations/django/__init__.py index db90918529..7eb91887df 100644 --- a/sentry_sdk/integrations/django/__init__.py +++ b/sentry_sdk/integrations/django/__init__.py @@ -69,7 +69,6 @@ def is_authenticated(request_user): # type: (Any) -> bool return request_user.is_authenticated() - else: def is_authenticated(request_user): @@ -202,7 +201,7 @@ def _django_queryset_repr(value, hint): # querysets. This might be surprising to the user but it's likely # less annoying. - return u"<%s from %s at 0x%x>" % ( + return "<%s from %s at 0x%x>" % ( value.__class__.__name__, value.__module__, id(value), diff --git a/sentry_sdk/integrations/pyramid.py b/sentry_sdk/integrations/pyramid.py index 980d56bb6f..07142254d2 100644 --- a/sentry_sdk/integrations/pyramid.py +++ b/sentry_sdk/integrations/pyramid.py @@ -40,7 +40,6 @@ def authenticated_userid(request): # type: (Request) -> Optional[Any] return request.authenticated_userid - else: # bw-compat for pyramid < 1.5 from pyramid.security import authenticated_userid # type: ignore diff --git a/sentry_sdk/integrations/wsgi.py b/sentry_sdk/integrations/wsgi.py index 4f274fa00c..803406fb6d 100644 --- a/sentry_sdk/integrations/wsgi.py +++ b/sentry_sdk/integrations/wsgi.py @@ -46,7 +46,6 @@ def wsgi_decoding_dance(s, charset="utf-8", errors="replace"): # type: (str, str, str) -> str return s.decode(charset, errors) - else: def wsgi_decoding_dance(s, charset="utf-8", errors="replace"): diff --git a/sentry_sdk/serializer.py b/sentry_sdk/serializer.py index 134528cd9a..e657f6b2b8 100644 --- a/sentry_sdk/serializer.py +++ b/sentry_sdk/serializer.py @@ -66,11 +66,11 @@ # Can be overwritten if wanting to send more bytes, e.g. with a custom server. # When changing this, keep in mind that events may be a little bit larger than # this value due to attached metadata, so keep the number conservative. -MAX_EVENT_BYTES = 10 ** 6 +MAX_EVENT_BYTES = 10**6 MAX_DATABAG_DEPTH = 5 MAX_DATABAG_BREADTH = 10 -CYCLE_MARKER = u"" +CYCLE_MARKER = "" global_repr_processors = [] # type: List[ReprProcessor] @@ -228,7 +228,7 @@ def _serialize_node( capture_internal_exception(sys.exc_info()) if is_databag: - return u"" + return "" return None finally: diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 48050350fb..1b5b65e1af 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -132,14 +132,17 @@ def init_span_recorder(self, maxlen): def __repr__(self): # type: () -> str - return "<%s(op=%r, description:%r, trace_id=%r, span_id=%r, parent_span_id=%r, sampled=%r)>" % ( - self.__class__.__name__, - self.op, - self.description, - self.trace_id, - self.span_id, - self.parent_span_id, - self.sampled, + return ( + "<%s(op=%r, description:%r, trace_id=%r, span_id=%r, parent_span_id=%r, sampled=%r)>" + % ( + self.__class__.__name__, + self.op, + self.description, + self.trace_id, + self.span_id, + self.parent_span_id, + self.sampled, + ) ) def __enter__(self): @@ -515,14 +518,17 @@ def __init__( def __repr__(self): # type: () -> str - return "<%s(name=%r, op=%r, trace_id=%r, span_id=%r, parent_span_id=%r, sampled=%r)>" % ( - self.__class__.__name__, - self.name, - self.op, - self.trace_id, - self.span_id, - self.parent_span_id, - self.sampled, + return ( + "<%s(name=%r, op=%r, trace_id=%r, span_id=%r, parent_span_id=%r, sampled=%r)>" + % ( + self.__class__.__name__, + self.name, + self.op, + self.trace_id, + self.span_id, + self.parent_span_id, + self.sampled, + ) ) @property diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index cc519a58a7..e22f6ae065 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -161,7 +161,7 @@ def __init__(self, value): return parts = urlparse.urlsplit(text_type(value)) - if parts.scheme not in (u"http", u"https"): + if parts.scheme not in ("http", "https"): raise BadDsn("Unsupported scheme %r" % parts.scheme) self.scheme = parts.scheme @@ -280,7 +280,7 @@ def to_header(self, timestamp=None): rv.append(("sentry_client", self.client)) if self.secret_key is not None: rv.append(("sentry_secret", self.secret_key)) - return u"Sentry " + u", ".join("%s=%s" % (key, value) for key, value in rv) + return "Sentry " + ", ".join("%s=%s" % (key, value) for key, value in rv) class AnnotatedValue(object): @@ -440,8 +440,7 @@ def safe_repr(value): return rv except Exception: # If e.g. the call to `repr` already fails - return u"" - + return "" else: @@ -606,7 +605,6 @@ def walk_exception_chain(exc_info): exc_value = cause tb = getattr(cause, "__traceback__", None) - else: def walk_exception_chain(exc_info): @@ -772,7 +770,7 @@ def strip_string(value, max_length=None): if length > max_length: return AnnotatedValue( - value=value[: max_length - 3] + u"...", + value=value[: max_length - 3] + "...", metadata={ "len": length, "rem": [["!limit", "x", max_length - 3, max_length]], diff --git a/setup.py b/setup.py index 9488b790ca..7db81e1308 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ def get_file_text(file_name): license="BSD", install_requires=["urllib3>=1.10.0", "certifi"], extras_require={ - "flask": ["flask>=0.11", "blinker>=1.1"], + "flask": ["flask>=0.11,<2.1.0", "blinker>=1.1"], "quart": ["quart>=0.16.1", "blinker>=1.1"], "bottle": ["bottle>=0.12.13"], "falcon": ["falcon>=1.4"], diff --git a/test-requirements.txt b/test-requirements.txt index ea8333ca16..746b10b9b4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ pytest<7 pytest-forked<=1.4.0 pytest-watch==4.2.0 tox==3.7.0 -Werkzeug +Werkzeug<2.1.0 pytest-localserver==0.5.0 pytest-cov==2.8.1 jsonschema==3.2.0 diff --git a/tests/conftest.py b/tests/conftest.py index 692a274d71..61f25d98ee 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -39,7 +39,6 @@ def benchmark(): return lambda x: x() - else: del pytest_benchmark diff --git a/tests/integrations/bottle/test_bottle.py b/tests/integrations/bottle/test_bottle.py index 16aacb55c5..ec133e4d75 100644 --- a/tests/integrations/bottle/test_bottle.py +++ b/tests/integrations/bottle/test_bottle.py @@ -196,7 +196,7 @@ def index(): assert len(event["request"]["data"]["foo"]) == 512 -@pytest.mark.parametrize("input_char", [u"a", b"a"]) +@pytest.mark.parametrize("input_char", ["a", b"a"]) def test_too_large_raw_request( sentry_init, input_char, capture_events, app, get_client ): diff --git a/tests/integrations/django/myapp/views.py b/tests/integrations/django/myapp/views.py index cac881552c..02c67ca150 100644 --- a/tests/integrations/django/myapp/views.py +++ b/tests/integrations/django/myapp/views.py @@ -29,7 +29,6 @@ def rest_hello(request): def rest_permission_denied_exc(request): raise PermissionDenied("bye") - except ImportError: pass diff --git a/tests/integrations/django/test_basic.py b/tests/integrations/django/test_basic.py index cc77c9a76a..6106131375 100644 --- a/tests/integrations/django/test_basic.py +++ b/tests/integrations/django/test_basic.py @@ -576,15 +576,15 @@ def test_template_exception( if with_executing_integration: assert filenames[-3:] == [ - (u"Parser.parse", u"django.template.base"), + ("Parser.parse", "django.template.base"), (None, None), - (u"Parser.invalid_block_tag", u"django.template.base"), + ("Parser.invalid_block_tag", "django.template.base"), ] else: assert filenames[-3:] == [ - (u"parse", u"django.template.base"), + ("parse", "django.template.base"), (None, None), - (u"invalid_block_tag", u"django.template.base"), + ("invalid_block_tag", "django.template.base"), ] diff --git a/tests/test_client.py b/tests/test_client.py index 9137f4115a..c8dd6955fe 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -496,7 +496,9 @@ def test_scope_initialized_before_client(sentry_init, capture_events): def test_weird_chars(sentry_init, capture_events): sentry_init() events = capture_events() + # fmt: off capture_message(u"föö".encode("latin1")) + # fmt: on (event,) = events assert json.loads(json.dumps(event)) == event @@ -812,7 +814,7 @@ def __repr__(self): "dsn", [ "http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2", - u"http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2", + "http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2", ], ) def test_init_string_types(dsn, sentry_init): diff --git a/tests/test_serializer.py b/tests/test_serializer.py index 1cc20c4b4a..f5ecc7560e 100644 --- a/tests/test_serializer.py +++ b/tests/test_serializer.py @@ -50,7 +50,9 @@ def inner(message, **kwargs): def test_bytes_serialization_decode(message_normalizer): binary = b"abc123\x80\xf0\x9f\x8d\x95" result = message_normalizer(binary, should_repr_strings=False) + # fmt: off assert result == u"abc123\ufffd\U0001f355" + # fmt: on @pytest.mark.xfail(sys.version_info < (3,), reason="Known safe_repr bugs in Py2.7") diff --git a/tests/utils/test_general.py b/tests/utils/test_general.py index 03be52ca17..b85975b4bb 100644 --- a/tests/utils/test_general.py +++ b/tests/utils/test_general.py @@ -31,19 +31,23 @@ def test_safe_repr_never_broken_for_strings(x): r = safe_repr(x) assert isinstance(r, text_type) - assert u"broken repr" not in r + assert "broken repr" not in r def test_safe_repr_regressions(): + # fmt: off assert u"лошадь" in safe_repr(u"лошадь") + # fmt: on @pytest.mark.xfail( sys.version_info < (3,), reason="Fixing this in Python 2 would break other behaviors", ) -@pytest.mark.parametrize("prefix", (u"", u"abcd", u"лошадь")) +# fmt: off +@pytest.mark.parametrize("prefix", ("", "abcd", u"лошадь")) @pytest.mark.parametrize("character", u"\x00\x07\x1b\n") +# fmt: on def test_safe_repr_non_printable(prefix, character): """Check that non-printable characters are escaped""" string = prefix + character @@ -129,49 +133,38 @@ def test_parse_invalid_dsn(dsn): @pytest.mark.parametrize("empty", [None, []]) def test_in_app(empty): - assert ( - handle_in_app_impl( - [{"module": "foo"}, {"module": "bar"}], - in_app_include=["foo"], - in_app_exclude=empty, - ) - == [{"module": "foo", "in_app": True}, {"module": "bar"}] - ) - - assert ( - handle_in_app_impl( - [{"module": "foo"}, {"module": "bar"}], - in_app_include=["foo"], - in_app_exclude=["foo"], - ) - == [{"module": "foo", "in_app": True}, {"module": "bar"}] - ) - - assert ( - handle_in_app_impl( - [{"module": "foo"}, {"module": "bar"}], - in_app_include=empty, - in_app_exclude=["foo"], - ) - == [{"module": "foo", "in_app": False}, {"module": "bar", "in_app": True}] - ) + assert handle_in_app_impl( + [{"module": "foo"}, {"module": "bar"}], + in_app_include=["foo"], + in_app_exclude=empty, + ) == [{"module": "foo", "in_app": True}, {"module": "bar"}] + + assert handle_in_app_impl( + [{"module": "foo"}, {"module": "bar"}], + in_app_include=["foo"], + in_app_exclude=["foo"], + ) == [{"module": "foo", "in_app": True}, {"module": "bar"}] + + assert handle_in_app_impl( + [{"module": "foo"}, {"module": "bar"}], + in_app_include=empty, + in_app_exclude=["foo"], + ) == [{"module": "foo", "in_app": False}, {"module": "bar", "in_app": True}] def test_iter_stacktraces(): - assert ( - set( - iter_event_stacktraces( - { - "threads": {"values": [{"stacktrace": 1}]}, - "stacktrace": 2, - "exception": {"values": [{"stacktrace": 3}]}, - } - ) + assert set( + iter_event_stacktraces( + { + "threads": {"values": [{"stacktrace": 1}]}, + "stacktrace": 2, + "exception": {"values": [{"stacktrace": 3}]}, + } ) - == {1, 2, 3} - ) + ) == {1, 2, 3} +# fmt: off @pytest.mark.parametrize( ("original", "base64_encoded"), [ @@ -191,6 +184,7 @@ def test_iter_stacktraces(): ), ], ) +# fmt: on def test_successful_base64_conversion(original, base64_encoded): # all unicode characters should be handled correctly assert to_base64(original) == base64_encoded