Skip to content

Commit 85208da

Browse files
authored
chore: Bump mypy and fix abstract ContextManager typing (#1421)
1 parent 8501874 commit 85208da

File tree

15 files changed

+35
-26
lines changed

15 files changed

+35
-26
lines changed

linter-requirements.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
black==22.3.0
22
flake8==3.9.2
33
flake8-import-order==0.18.1
4-
mypy==0.782
4+
mypy==0.950
5+
types-certifi
6+
types-redis
7+
types-setuptools
58
flake8-bugbear==21.4.3
69
pep8-naming==0.11.1
7-
pre-commit # local linting
10+
pre-commit # local linting

mypy.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ ignore_missing_imports = True
6161
disallow_untyped_defs = False
6262
[mypy-celery.app.trace]
6363
ignore_missing_imports = True
64+
[mypy-flask.signals]
65+
ignore_missing_imports = True

sentry_sdk/hub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _init(*args, **kwargs):
117117
# Use `ClientConstructor` to define the argument types of `init` and
118118
# `ContextManager[Any]` to tell static analyzers about the return type.
119119

120-
class init(ClientConstructor, ContextManager[Any]): # noqa: N801
120+
class init(ClientConstructor, _InitGuard): # noqa: N801
121121
pass
122122

123123
else:

sentry_sdk/integrations/aws_lambda.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,12 @@ def get_lambda_bootstrap():
302302
module = sys.modules["__main__"]
303303
# python3.9 runtime
304304
if hasattr(module, "awslambdaricmain") and hasattr(
305-
module.awslambdaricmain, "bootstrap" # type: ignore
305+
module.awslambdaricmain, "bootstrap"
306306
):
307-
return module.awslambdaricmain.bootstrap # type: ignore
307+
return module.awslambdaricmain.bootstrap
308308
elif hasattr(module, "bootstrap"):
309309
# awslambdaric python module in container builds
310-
return module.bootstrap # type: ignore
310+
return module.bootstrap
311311

312312
# python3.8 runtime
313313
return module

sentry_sdk/integrations/celery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
try:
26-
from celery import VERSION as CELERY_VERSION # type: ignore
26+
from celery import VERSION as CELERY_VERSION
2727
from celery.exceptions import ( # type: ignore
2828
SoftTimeLimitExceeded,
2929
Retry,

sentry_sdk/integrations/excepthook.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
from typing import Callable
1111
from typing import Any
1212
from typing import Type
13+
from typing import Optional
1314

1415
from types import TracebackType
1516

1617
Excepthook = Callable[
17-
[Type[BaseException], BaseException, TracebackType],
18+
[Type[BaseException], BaseException, Optional[TracebackType]],
1819
Any,
1920
]
2021

@@ -43,7 +44,7 @@ def setup_once():
4344
def _make_excepthook(old_excepthook):
4445
# type: (Excepthook) -> Excepthook
4546
def sentry_sdk_excepthook(type_, value, traceback):
46-
# type: (Type[BaseException], BaseException, TracebackType) -> None
47+
# type: (Type[BaseException], BaseException, Optional[TracebackType]) -> None
4748
hub = Hub.current
4849
integration = hub.get_integration(ExcepthookIntegration)
4950

sentry_sdk/integrations/flask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def sentry_patched_wsgi_app(self, environ, start_response):
9494
environ, start_response
9595
)
9696

97-
Flask.__call__ = sentry_patched_wsgi_app # type: ignore
97+
Flask.__call__ = sentry_patched_wsgi_app
9898

9999

100100
def _add_sentry_trace(sender, template, context, **extra):

sentry_sdk/integrations/gcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def __init__(self, timeout_warning=False):
126126
@staticmethod
127127
def setup_once():
128128
# type: () -> None
129-
import __main__ as gcp_functions # type: ignore
129+
import __main__ as gcp_functions
130130

131131
if not hasattr(gcp_functions, "worker_v1"):
132132
logger.warning(

sentry_sdk/integrations/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _handle_record(self, record):
7878
@staticmethod
7979
def setup_once():
8080
# type: () -> None
81-
old_callhandlers = logging.Logger.callHandlers # type: ignore
81+
old_callhandlers = logging.Logger.callHandlers
8282

8383
def sentry_patched_callhandlers(self, record):
8484
# type: (Any, LogRecord) -> Any

sentry_sdk/integrations/sqlalchemy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _after_cursor_execute(conn, cursor, statement, parameters, context, *args):
7070
# type: (Any, Any, Any, Any, Any, *Any) -> None
7171
ctx_mgr = getattr(
7272
context, "_sentry_sql_span_manager", None
73-
) # type: ContextManager[Any]
73+
) # type: Optional[ContextManager[Any]]
7474

7575
if ctx_mgr is not None:
7676
context._sentry_sql_span_manager = None
@@ -93,7 +93,7 @@ def _handle_error(context, *args):
9393
# handler is going to be fatal.
9494
ctx_mgr = getattr(
9595
execution_context, "_sentry_sql_span_manager", None
96-
) # type: ContextManager[Any]
96+
) # type: Optional[ContextManager[Any]]
9797

9898
if ctx_mgr is not None:
9999
execution_context._sentry_sql_span_manager = None

0 commit comments

Comments
 (0)