Skip to content

Commit e2dd1f6

Browse files
authored
Small (compatibility) fixes (getsentry#2663)
1 parent 9561fff commit e2dd1f6

7 files changed

Lines changed: 16 additions & 42 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ format: .venv
3030
.PHONY: format
3131

3232
test: .venv
33-
@$(VENV_PATH)/bin/tox -e py3.9
33+
@$(VENV_PATH)/bin/tox -e py3.12
3434
.PHONY: test
3535

3636
test-all: .venv

scripts/build_aws_lambda_layer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def install_python_packages(self):
5252

5353
sentry_python_sdk = os.path.join(
5454
DIST_PATH,
55-
f"sentry_sdk-{SDK_VERSION}-py2.py3-none-any.whl", # this is generated by "make dist" that is called by "make aws-lamber-layer"
55+
f"sentry_sdk-{SDK_VERSION}-py2.py3-none-any.whl", # this is generated by "make dist" that is called by "make aws-lambda-layer"
5656
)
5757
subprocess.run(
5858
[

scripts/init_serverless_sdk.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,15 @@ def extract_and_load_lambda_function_module(self, module_path):
4848
module_name = module_path.split(os.path.sep)[-1]
4949
module_file_path = module_path + ".py"
5050

51-
# Supported python versions are 2.7, 3.6, 3.7, 3.8
52-
if py_version >= (3, 5):
51+
# Supported python versions are 3.6, 3.7, 3.8
52+
if py_version >= (3, 6):
5353
import importlib.util
5454

5555
spec = importlib.util.spec_from_file_location(
5656
module_name, module_file_path
5757
)
5858
self.lambda_function_module = importlib.util.module_from_spec(spec)
5959
spec.loader.exec_module(self.lambda_function_module)
60-
elif py_version[0] < 3:
61-
import imp
62-
63-
self.lambda_function_module = imp.load_source(
64-
module_name, module_file_path
65-
)
6660
else:
6761
raise ValueError("Python version %s is not supported." % py_version)
6862
else:

sentry_sdk/hub.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,10 @@ def __exit__(self, exc_type, exc_value, tb):
110110

111111
def _check_python_deprecations():
112112
# type: () -> None
113-
version = sys.version_info[:2]
114-
115-
if version == (3, 4) or version == (3, 5):
116-
logger.warning(
117-
"sentry-sdk 2.0.0 will drop support for Python %s.",
118-
"{}.{}".format(*version),
119-
)
120-
logger.warning(
121-
"Please upgrade to the latest version to continue receiving upgrades and bugfixes."
122-
)
113+
# Since we're likely to deprecate Python versions in the future, I'm keeping
114+
# this handy function around. Use this to detect the Python version used and
115+
# to output logger.warning()s if it's deprecated.
116+
pass
123117

124118

125119
def _init(*args, **kwargs):

sentry_sdk/integrations/aws_lambda.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def setup_once():
210210
)
211211
return
212212

213-
pre_37 = hasattr(lambda_bootstrap, "handle_http_request") # Python 3.6 or 2.7
213+
pre_37 = hasattr(lambda_bootstrap, "handle_http_request") # Python 3.6
214214

215215
if pre_37:
216216
old_handle_event_request = lambda_bootstrap.handle_event_request
@@ -286,8 +286,6 @@ def inner(*args, **kwargs):
286286
def get_lambda_bootstrap():
287287
# type: () -> Optional[Any]
288288

289-
# Python 2.7: Everything is in `__main__`.
290-
#
291289
# Python 3.7: If the bootstrap module is *already imported*, it is the
292290
# one we actually want to use (no idea what's in __main__)
293291
#

sentry_sdk/integrations/django/middleware.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@
2828
"import_string_should_wrap_middleware"
2929
)
3030

31-
if DJANGO_VERSION < (1, 7):
32-
import_string_name = "import_by_path"
33-
else:
34-
import_string_name = "import_string"
35-
36-
3731
if DJANGO_VERSION < (3, 1):
3832
_asgi_middleware_mixin_factory = lambda _: object
3933
else:
@@ -44,7 +38,7 @@ def patch_django_middlewares():
4438
# type: () -> None
4539
from django.core.handlers import base
4640

47-
old_import_string = getattr(base, import_string_name)
41+
old_import_string = base.import_string
4842

4943
def sentry_patched_import_string(dotted_path):
5044
# type: (str) -> Any
@@ -55,7 +49,7 @@ def sentry_patched_import_string(dotted_path):
5549

5650
return rv
5751

58-
setattr(base, import_string_name, sentry_patched_import_string)
52+
base.import_string = sentry_patched_import_string
5953

6054
old_load_middleware = base.BaseHandler.load_middleware
6155

sentry_sdk/integrations/stdlib.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import subprocess
33
import sys
44
import platform
5-
from sentry_sdk.consts import OP, SPANDATA
5+
from http.client import HTTPConnection
66

7+
from sentry_sdk.consts import OP, SPANDATA
78
from sentry_sdk.hub import Hub
89
from sentry_sdk.integrations import Integration
910
from sentry_sdk.scope import add_global_event_processor
@@ -16,7 +17,6 @@
1617
safe_repr,
1718
parse_url,
1819
)
19-
2020
from sentry_sdk._types import TYPE_CHECKING
2121

2222
if TYPE_CHECKING:
@@ -29,12 +29,6 @@
2929
from sentry_sdk._types import Event, Hint
3030

3131

32-
try:
33-
from httplib import HTTPConnection # type: ignore
34-
except ImportError:
35-
from http.client import HTTPConnection
36-
37-
3832
_RUNTIME_CONTEXT = {
3933
"name": platform.python_implementation(),
4034
"version": "%s.%s.%s" % (sys.version_info[:3]),
@@ -114,7 +108,7 @@ def putrequest(self, method, url, *args, **kwargs):
114108
)
115109
self.putheader(key, value)
116110

117-
self._sentrysdk_span = span
111+
self._sentrysdk_span = span # type: ignore[attr-defined]
118112

119113
return rv
120114

@@ -133,8 +127,8 @@ def getresponse(self, *args, **kwargs):
133127

134128
return rv
135129

136-
HTTPConnection.putrequest = putrequest
137-
HTTPConnection.getresponse = getresponse
130+
HTTPConnection.putrequest = putrequest # type: ignore[method-assign]
131+
HTTPConnection.getresponse = getresponse # type: ignore[method-assign]
138132

139133

140134
def _init_argument(args, kwargs, name, position, setdefault_callback=None):

0 commit comments

Comments
 (0)