Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions sentry_sdk/_compat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import sys
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any, TypeVar

T = TypeVar("T")


PY37 = sys.version_info[0] == 3 and sys.version_info[1] >= 7
Expand All @@ -13,14 +7,6 @@
PY311 = sys.version_info[0] == 3 and sys.version_info[1] >= 11


def with_metaclass(meta: "Any", *bases: "Any") -> "Any":
class MetaClass(type):
def __new__(metacls: "Any", name: "Any", this_bases: "Any", d: "Any") -> "Any":
return meta(name, bases, d)

return type.__new__(MetaClass, "temporary_class", (), {})


def check_uwsgi_thread_support() -> bool:
# We check two things here:
#
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class _Client(BaseClient):
"""

def __init__(self, *args: "Any", **kwargs: "Any") -> None:
super(_Client, self).__init__(options=get_options(*args, **kwargs))
super().__init__(options=get_options(*args, **kwargs))
self._init_impl()

def __getstate__(self) -> "Any":
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
get_global_scope,
get_isolation_scope,
)
from sentry_sdk._compat import with_metaclass
from sentry_sdk.client import Client
from sentry_sdk.consts import INSTRUMENTER
from sentry_sdk.scope import _ScopeManager
Expand Down Expand Up @@ -109,7 +108,7 @@ def main(cls) -> "Hub":
return GLOBAL_HUB


class Hub(with_metaclass(HubMeta)): # type: ignore
class Hub(metaclass=HubMeta):
"""
.. deprecated:: 2.0.0
The Hub is deprecated. Its functionality will be merged into :py:class:`sentry_sdk.scope.Scope`.
Expand Down
1 change: 0 additions & 1 deletion sentry_sdk/integrations/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def sync_sentry_wrapped_method(*args: "Any", **kwargs: "Any") -> "Any":
sentry_wrapped_method = sync_sentry_wrapped_method

try:
# fails for __call__ of function on Python 2 (see py2.7-django-1.11)
sentry_wrapped_method = wraps(old_method)(sentry_wrapped_method)

# Necessary for Django 3.1
Expand Down
2 changes: 0 additions & 2 deletions sentry_sdk/integrations/django/signals_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def _get_receiver_name(receiver: "Callable[..., Any]") -> str:

if hasattr(receiver, "__qualname__"):
name = receiver.__qualname__
elif hasattr(receiver, "__name__"): # Python 2.7 has no __qualname__
name = receiver.__name__
Comment on lines -21 to -22

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not every function has __qualname__ in Python, so this is not purely Python 2 compat.

elif hasattr(
receiver, "func"
): # certain functions (like partials) dont have a name
Expand Down
30 changes: 12 additions & 18 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,9 @@ def __init__(
elif isinstance(start_timestamp, float):
start_timestamp = datetime.fromtimestamp(start_timestamp, timezone.utc)
self.start_timestamp = start_timestamp
try:
# profiling depends on this value and requires that
# it is measured in nanoseconds
self._start_timestamp_monotonic_ns = nanosecond_time()
except AttributeError:
pass
# profiling depends on this value and requires that
# it is measured in nanoseconds
self._start_timestamp_monotonic_ns = nanosecond_time()

#: End timestamp of span
self.timestamp: "Optional[datetime]" = None
Expand Down Expand Up @@ -675,18 +672,15 @@ def finish(
# This span is already finished, ignore.
return None

try:
if end_timestamp:
if isinstance(end_timestamp, float):
end_timestamp = datetime.fromtimestamp(end_timestamp, timezone.utc)
self.timestamp = end_timestamp
else:
elapsed = nanosecond_time() - self._start_timestamp_monotonic_ns
self.timestamp = self.start_timestamp + timedelta(
microseconds=elapsed / 1000
)
except AttributeError:
self.timestamp = datetime.now(timezone.utc)
if end_timestamp:
if isinstance(end_timestamp, float):
end_timestamp = datetime.fromtimestamp(end_timestamp, timezone.utc)
self.timestamp = end_timestamp
else:
elapsed = nanosecond_time() - self._start_timestamp_monotonic_ns
self.timestamp = self.start_timestamp + timedelta(
microseconds=elapsed / 1000
)

scope = scope or sentry_sdk.get_current_scope()

Expand Down
8 changes: 3 additions & 5 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def get_git_revision() -> "Optional[str]":
.strip()
.decode("utf-8")
)
except (OSError, IOError, FileNotFoundError):
except OSError:
return None

return revision
Expand Down Expand Up @@ -484,15 +484,15 @@ def get_lines_from_file(
if loader is not None and hasattr(loader, "get_source"):
try:
source_str: "Optional[str]" = loader.get_source(module)
except (ImportError, IOError):
except (ImportError, OSError):
source_str = None
if source_str is not None:
source = source_str.splitlines()

if source is None:
try:
source = linecache.getlines(filename)
except (OSError, IOError):
except OSError:
return [], None, []

if not source:
Expand Down Expand Up @@ -1527,8 +1527,6 @@ def qualname_from_function(func: "Callable[..., Any]") -> "Optional[str]":

if hasattr(func, "__qualname__"):
func_qualname = func.__qualname__
elif hasattr(func, "__name__"):
func_qualname = func.__name__

if func_qualname is not None:
if hasattr(func, "__module__") and isinstance(func.__module__, str):
Expand Down
5 changes: 1 addition & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,6 @@ def __eq__(self, test_string):
if not isinstance(test_string, self.valid_types):
return False

# this is safe even in py2 because as of 2.6, `bytes` exists in py2
# as an alias for `str`
if isinstance(test_string, bytes):
test_string = test_string.decode()

Expand All @@ -707,8 +705,7 @@ def _safe_is_equal(x, y):
Compares two values, preferring to use the first's __eq__ method if it
exists and is implemented.

Accounts for py2/py3 differences (like ints in py2 not having a __eq__
method), as well as the incomparability of certain types exposed by using
Accounts for the incomparability of certain types exposed by using
raw __eq__ () rather than ==.
"""

Expand Down