From 60a325c748542a94c20f300274ee0dcb20ceca50 Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Mon, 22 Jan 2024 12:05:33 +0100 Subject: [PATCH 1/6] Remove more compatibility code and comments --- Makefile | 2 +- scripts/build_aws_lambda_layer.py | 2 +- scripts/init_serverless_sdk.py | 10 ++-------- sentry_sdk/hub.py | 12 ++---------- sentry_sdk/integrations/aws_lambda.py | 4 +--- 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 32cdbb1fff..7d5850f04d 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ format: .venv .PHONY: format test: .venv - @$(VENV_PATH)/bin/tox -e py3.9 + @$(VENV_PATH)/bin/tox -e py3.12 .PHONY: test test-all: .venv diff --git a/scripts/build_aws_lambda_layer.py b/scripts/build_aws_lambda_layer.py index 8704e4de01..c2cb46f0bb 100644 --- a/scripts/build_aws_lambda_layer.py +++ b/scripts/build_aws_lambda_layer.py @@ -52,7 +52,7 @@ def install_python_packages(self): sentry_python_sdk = os.path.join( DIST_PATH, - f"sentry_sdk-{SDK_VERSION}-py2.py3-none-any.whl", # this is generated by "make dist" that is called by "make aws-lamber-layer" + f"sentry_sdk-{SDK_VERSION}-py2.py3-none-any.whl", # this is generated by "make dist" that is called by "make aws-lambda-layer" ) subprocess.run( [ diff --git a/scripts/init_serverless_sdk.py b/scripts/init_serverless_sdk.py index e620c1067b..57b77c9cbe 100644 --- a/scripts/init_serverless_sdk.py +++ b/scripts/init_serverless_sdk.py @@ -48,8 +48,8 @@ def extract_and_load_lambda_function_module(self, module_path): module_name = module_path.split(os.path.sep)[-1] module_file_path = module_path + ".py" - # Supported python versions are 2.7, 3.6, 3.7, 3.8 - if py_version >= (3, 5): + # Supported python versions are 3.6, 3.7, 3.8 + if py_version >= (3, 6): import importlib.util spec = importlib.util.spec_from_file_location( @@ -57,12 +57,6 @@ def extract_and_load_lambda_function_module(self, module_path): ) self.lambda_function_module = importlib.util.module_from_spec(spec) spec.loader.exec_module(self.lambda_function_module) - elif py_version[0] < 3: - import imp - - self.lambda_function_module = imp.load_source( - module_name, module_file_path - ) else: raise ValueError("Python version %s is not supported." % py_version) else: diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index 3ee2adf255..600595153e 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -110,16 +110,8 @@ def __exit__(self, exc_type, exc_value, tb): def _check_python_deprecations(): # type: () -> None - version = sys.version_info[:2] - - if version == (3, 4) or version == (3, 5): - logger.warning( - "sentry-sdk 2.0.0 will drop support for Python %s.", - "{}.{}".format(*version), - ) - logger.warning( - "Please upgrade to the latest version to continue receiving upgrades and bugfixes." - ) + # Use this to output logger.warnings for deprecated Python versions + pass def _init(*args, **kwargs): diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index a83da3b5f3..072d9a6fa7 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -210,7 +210,7 @@ def setup_once(): ) return - pre_37 = hasattr(lambda_bootstrap, "handle_http_request") # Python 3.6 or 2.7 + pre_37 = hasattr(lambda_bootstrap, "handle_http_request") # Python 3.6 if pre_37: old_handle_event_request = lambda_bootstrap.handle_event_request @@ -286,8 +286,6 @@ def inner(*args, **kwargs): def get_lambda_bootstrap(): # type: () -> Optional[Any] - # Python 2.7: Everything is in `__main__`. - # # Python 3.7: If the bootstrap module is *already imported*, it is the # one we actually want to use (no idea what's in __main__) # From 6cd626338ef3b7cbed4f9fcb0211af0ac10d1f6b Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Mon, 22 Jan 2024 12:18:46 +0100 Subject: [PATCH 2/6] wip --- sentry_sdk/integrations/django/middleware.py | 10 ++-------- sentry_sdk/integrations/stdlib.py | 10 ++-------- tests/integrations/rediscluster/test_rediscluster.py | 10 +++------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/sentry_sdk/integrations/django/middleware.py b/sentry_sdk/integrations/django/middleware.py index fc39466c13..a84665122b 100644 --- a/sentry_sdk/integrations/django/middleware.py +++ b/sentry_sdk/integrations/django/middleware.py @@ -28,12 +28,6 @@ "import_string_should_wrap_middleware" ) -if DJANGO_VERSION < (1, 7): - import_string_name = "import_by_path" -else: - import_string_name = "import_string" - - if DJANGO_VERSION < (3, 1): _asgi_middleware_mixin_factory = lambda _: object else: @@ -44,7 +38,7 @@ def patch_django_middlewares(): # type: () -> None from django.core.handlers import base - old_import_string = getattr(base, import_string_name) + old_import_string = getattr(base, "import_string") def sentry_patched_import_string(dotted_path): # type: (str) -> Any @@ -55,7 +49,7 @@ def sentry_patched_import_string(dotted_path): return rv - setattr(base, import_string_name, sentry_patched_import_string) + setattr(base, "import_string", sentry_patched_import_string) old_load_middleware = base.BaseHandler.load_middleware diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index a5c3bfb2ae..6e1ca97510 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -2,8 +2,9 @@ import subprocess import sys import platform -from sentry_sdk.consts import OP, SPANDATA +from http.client import HTTPConnection +from sentry_sdk.consts import OP, SPANDATA from sentry_sdk.hub import Hub from sentry_sdk.integrations import Integration from sentry_sdk.scope import add_global_event_processor @@ -16,7 +17,6 @@ safe_repr, parse_url, ) - from sentry_sdk._types import TYPE_CHECKING if TYPE_CHECKING: @@ -29,12 +29,6 @@ from sentry_sdk._types import Event, Hint -try: - from httplib import HTTPConnection # type: ignore -except ImportError: - from http.client import HTTPConnection - - _RUNTIME_CONTEXT = { "name": platform.python_implementation(), "version": "%s.%s.%s" % (sys.version_info[:3]), diff --git a/tests/integrations/rediscluster/test_rediscluster.py b/tests/integrations/rediscluster/test_rediscluster.py index 14d831a647..34ec1f4213 100644 --- a/tests/integrations/rediscluster/test_rediscluster.py +++ b/tests/integrations/rediscluster/test_rediscluster.py @@ -1,17 +1,13 @@ import pytest +from unittest import mock + +import rediscluster from sentry_sdk import capture_message from sentry_sdk.api import start_transaction from sentry_sdk.consts import SPANDATA from sentry_sdk.integrations.redis import RedisIntegration -try: - from unittest import mock -except ImportError: - import mock - -import rediscluster - MOCK_CONNECTION_POOL = mock.MagicMock() MOCK_CONNECTION_POOL.connection_kwargs = { From ca8411597a5d11ef861b95e9af8076f9c907e86e Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Mon, 22 Jan 2024 13:42:48 +0100 Subject: [PATCH 3/6] change getattr, setattr with constant attrs --- sentry_sdk/integrations/django/middleware.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/django/middleware.py b/sentry_sdk/integrations/django/middleware.py index a84665122b..fbb03c1641 100644 --- a/sentry_sdk/integrations/django/middleware.py +++ b/sentry_sdk/integrations/django/middleware.py @@ -38,7 +38,7 @@ def patch_django_middlewares(): # type: () -> None from django.core.handlers import base - old_import_string = getattr(base, "import_string") + old_import_string = base.import_string def sentry_patched_import_string(dotted_path): # type: (str) -> Any @@ -49,7 +49,7 @@ def sentry_patched_import_string(dotted_path): return rv - setattr(base, "import_string", sentry_patched_import_string) + base.import_string = sentry_patched_import_string old_load_middleware = base.BaseHandler.load_middleware From d81b589211416918f9950634f7b6c9aec11a5905 Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Mon, 22 Jan 2024 13:48:37 +0100 Subject: [PATCH 4/6] typing --- sentry_sdk/integrations/stdlib.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index 6e1ca97510..3677230606 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -108,7 +108,7 @@ def putrequest(self, method, url, *args, **kwargs): ) self.putheader(key, value) - self._sentrysdk_span = span + self._sentrysdk_span = span # type: ignore[attr-defined] return rv @@ -127,8 +127,8 @@ def getresponse(self, *args, **kwargs): return rv - HTTPConnection.putrequest = putrequest - HTTPConnection.getresponse = getresponse + HTTPConnection.putrequest = putrequest # type: ignore[method-assign] + HTTPConnection.getresponse = getresponse # type: ignore[method-assign] def _init_argument(args, kwargs, name, position, setdefault_callback=None): From b9f810c03fa93c28f9bc2b51f97992115fc7d34a Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Mon, 22 Jan 2024 17:33:19 +0100 Subject: [PATCH 5/6] clarify comment --- sentry_sdk/hub.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index 600595153e..a68e595f86 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -110,7 +110,9 @@ def __exit__(self, exc_type, exc_value, tb): def _check_python_deprecations(): # type: () -> None - # Use this to output logger.warnings for deprecated Python versions + # Since we're likely to deprecate Python versions in the future, I'm keeping + # this handy function around. Use this to output logger.warning()s if the user + # is on a Python version that's deprecated at that point in time. pass From ae0686e2690f37d1bdadc4fd2ef6fa05885fbbda Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Mon, 22 Jan 2024 17:34:39 +0100 Subject: [PATCH 6/6] wording --- sentry_sdk/hub.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index a68e595f86..9f6f9985c0 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -111,8 +111,8 @@ def __exit__(self, exc_type, exc_value, tb): def _check_python_deprecations(): # type: () -> None # Since we're likely to deprecate Python versions in the future, I'm keeping - # this handy function around. Use this to output logger.warning()s if the user - # is on a Python version that's deprecated at that point in time. + # this handy function around. Use this to detect the Python version used and + # to output logger.warning()s if it's deprecated. pass