10000 ref: Make mypy stricter · etherscan-io/sentry-python@5347575 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5347575

Browse files
committed
ref: Make mypy stricter
1 parent 5e1efaf commit 5347575

20 files changed

+161
-72
lines changed

mypy.ini

Lines changed: 98 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,116 @@ strict_equality = True
1616
strict_optional = True
1717
warn_redundant_casts = True
1818
; warn_return_any = True
19-
; warn_unused_configs = True
20-
; warn_unused_ignores = True
19+
warn_unused_configs = True
20+
warn_unused_ignores = True
2121

2222

23-
; Relaxations:
23+
; Relaxations for code written before mypy was introduced
24+
;
25+
; Do not use wildcards in module paths, otherwise added modules will
26+
; automatically have the same set of relaxed rules as the rest
2427

2528
[mypy-sentry_sdk._compat]
2629
disallow_untyped_defs = False
2730

2831
[mypy-sentry_sdk.scope]
2932
disallow_untyped_defs = False
3033

31-
[mypy-sentry_sdk.integrations.*]
34+
[mypy-sentry_sdk.integrations.django]
3235
disallow_any_generics = False
3336
disallow_untyped_defs = False
3437

35-
[mypy-sentry_sdk.integrations.aiohttp]
36-
disallow_any_generics = True
37-
disallow_untyped_defs = True
38+
[mypy-sentry_sdk.integrations.django.middleware]
39+
disallow_any_generics = False
40+
disallow_untyped_defs = False
41+
42+
[mypy-sentry_sdk.integrations.bottle]
43+
disallow_any_generics = False
44+
disallow_untyped_defs = False
45+
46+
[mypy-sentry_sdk.integrations.flask]
47+
disallow_any_generics = False
48+
disallow_untyped_defs = False
49+
50+
[mypy-sentry_sdk.integrations.asgi]
51+
disallow_any_generics = False
52+
disallow_untyped_defs = False
53+
54+
[mypy-sentry_sdk.integrations.falcon]
55+
disallow_any_generics = False
56+
disallow_untyped_defs = False
57+
58+
[mypy-sentry_sdk.integrations.aws_lambda]
59+
disallow_any_generics = False
60+
disallow_untyped_defs = False
61+
62+
[mypy-sentry_sdk.integrations.pyramid]
63+
disallow_any_generics = False
64+
disallow_untyped_defs = False
65+
66+
[mypy-sentry_sdk.integrations.celery]
67+
disallow_any_generics = False
68+
disallow_untyped_defs = False
69+
70+
[mypy-sentry_sdk.integrations.beam]
71+
disallow_any_generics = False
72+
disallow_untyped_defs = False
73+
74+
[mypy-sentry_sdk.integrations.sanic]
75+
disallow_any_generics = False
76+
disallow_untyped_defs = False
77+
78+
[mypy-sentry_sdk.integrations.tornado]
79+
disallow_any_generics = False
80+
disallow_untyped_defs = False
81+
82+
[mypy-sentry_sdk.integrations.atexit]
83+
disallow_any_generics = False
84+
disallow_untyped_defs = False
85+
86+
[mypy-sentry_sdk.integrations._wsgi_common]
87+
disallow_any_generics = False
88+
disallow_untyped_defs = False
89+
90+
[mypy-sentry_sdk.integrations.wsgi]
91+
disallow_any_generics = False
92+
disallow_untyped_defs = False
93+
94+
[mypy-sentry_sdk.integrations.serverless]
95+
disallow_any_generics = False
96+
disallow_untyped_defs = False
97+
98+
[mypy-sentry_sdk.integrations.excepthook]
99+
disallow_any_generics = False
100+
disallow_untyped_defs = False
101+
102+
[mypy-sentry_sdk.integrations.threading]
103+
disallow_any_generics = False
104+
disallow_untyped_defs = False
105+
106+
[mypy-sentry_sdk.integrations.stdlib]
107+
disallow_any_generics = False
108+
disallow_untyped_defs = False
109+
110+
[mypy-sentry_sdk.integrations.sqlalchemy]
111+
disallow_any_generics = False
112+
disallow_untyped_defs = False
113+
114+
[mypy-sentry_sdk.integrations.rq]
115+
disallow_any_generics = False
116+
disallow_untyped_defs = False
117+
118+
[mypy-sentry_sdk.integrations.redis]
119+
disallow_any_generics = False
120+
disallow_untyped_defs = False
121+
122+
[mypy-sentry_sdk.integrations.gnu_backtrace]
123+
disallow_any_generics = False
124+
disallow_untyped_defs = False
125+
126+
[mypy-sentry_sdk.integrations.django.templates]
127+
disallow_any_generics = False
128+
disallow_untyped_defs = False
38129

39130
[mypy-sentry_sdk.utils]
40131
disallow_any_generics = False

sentry_sdk/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _get_options(*args, **kwargs):
4545
rv = dict(DEFAULT_OPTIONS)
4646
options = dict(*args, **kwargs) # type: ignore
4747
if dsn is not None and options.get("dsn") is None:
48-
options["dsn"] = dsn # type: ignore
48+
options["dsn"] = dsn
4949

5050
for key, value in iteritems(options):
5151
if key not in rv:
@@ -64,7 +64,7 @@ def _get_options(*args, **kwargs):
6464
if rv["server_name"] is None and hasattr(socket, "gethostname"):
6565
rv["server_name"] = socket.gethostname()
6666

67-
return rv # type: ignore
67+
return rv
6868

6969

7070
class _Client(object):
@@ -154,8 +154,8 @@ def _prepare_event(
154154
}
155155

156156
for key in "release", "environment", "server_name", "dist":
157-
if event.get(key) is None and self.options[key] is not None: # type: ignore
158-
event[key] = text_type(self.options[key]).strip() # type: ignore
157+
if event.get(key) is None and self.options[key] is not None:
158+
event[key] = text_type(self.options[key]).strip()
159159
if event.get("sdk") is None:
160160
sdk_info = dict(SDK_INFO)
161161
sdk_info["integrations"] = sorted(self.integrations.keys())
@@ -200,7 +200,7 @@ def _is_ignored_error(self, event, hint):
200200
if errcls == full_name or errcls == type_name:
201201
return True
202202
else:
203-
if issubclass(exc_info[0], errcls): # type: ignore
203+
if issubclass(exc_info[0], errcls):
204204
return True
205205

206206
return False

sentry_sdk/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _get_default_options():
6060
import inspect
6161

6262
if hasattr(inspect, "getfullargspec"):
63-
getargspec = inspect.getfullargspec # type: ignore
63+
getargspec = inspect.getfullargspec
6464
else:
6565
getargspec = inspect.getargspec # type: ignore
6666

sentry_sdk/hub.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def overload(x):
4646
return x
4747

4848

49-
_local = ContextVar("sentry_current_hub") # type: ignore
49+
_local = ContextVar("sentry_current_hub")
5050
_initial_client = None # type: Optional[weakref.ReferenceType[Client]]
5151

5252

@@ -370,7 +370,7 @@ def _capture_internal_exception(
370370
371371
These exceptions do not end up in Sentry and are just logged instead.
372372
"""
373-
logger.error("Internal error in sentry_sdk", exc_info=exc_info) # type: ignore
373+
logger.error("Internal error in sentry_sdk", exc_info=exc_info)
374374

375375
def add_breadcrumb(
376376
self,

sentry_sdk/integrations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def setup_integrations(integrations, with_defaults=True):
7272
instance = integration_cls()
7373
integrations[instance.identifier] = instance
7474

75-
for identifier, integration in iteritems(integrations): # type: ignore
75+
for identifier, integration in iteritems(integrations):
7676
with _installer_lock:
7777
if identifier not in _installed_integrations:
7878
logger.debug(

sentry_sdk/integrations/aiohttp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
)
1515

1616
import asyncio
17-
from aiohttp.web import Application, HTTPException, UrlDispatcher # type: ignore
17+
from aiohttp.web import Application, HTTPException, UrlDispatcher
1818

1919
from sentry_sdk._types import MYPY
2020

2121
if MYPY:
22-
from aiohttp.web_request import Request # type: ignore
23-
from aiohttp.abc import AbstractMatchInfo # type: ignore
22+
from aiohttp.web_request import Request
23+
from aiohttp.abc import AbstractMatchInfo
2424
from typing import Any
2525
from typing import Dict
2626
from typing import Tuple

sentry_sdk/integrations/bottle.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
from typing import Optional
2222
from bottle import FileUpload, FormsDict, LocalRequest # type: ignore
2323

24-
from bottle import (
25-
Bottle,
26-
Route,
27-
request as bottle_request,
28-
HTTPResponse,
29-
) # type: ignore
24+
from bottle import Bottle, Route, request as bottle_request, HTTPResponse
3025

3126

3227
class BottleIntegration(Integration):
@@ -63,7 +58,7 @@ def sentry_patched_wsgi_app(self, environ, start_response):
6358
environ, start_response
6459
)
6560

66-
Bottle.__call__ = sentry_patched_wsgi_app # type: ignore
61+
Bottle.__call__ = sentry_patched_wsgi_app
6762

6863
# monkey patch method Bottle._handle
6964
old_handle = Bottle._handle
@@ -170,7 +165,7 @@ def inner(event, hint):
170165
request.route.callback
171166
)
172167
elif integration.transaction_style == "url":
173-
event["transaction"] = request.route.rule # type: ignore
168+
event["transaction"] = request.route.rule
174169
except Exception:
175170
pass
176171

sentry_sdk/integrations/django/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import threading
66
import weakref
77

8-
from django import VERSION as DJANGO_VERSION # type: ignore
9-
from django.core import signals # type: ignore
8+
from django import VERSION as DJANGO_VERSION
9+
from django.core import signals
1010

1111
from sentry_sdk._types import MYPY
1212
from sentry_sdk.utils import HAS_REAL_CONTEXTVARS
@@ -18,19 +18,19 @@
1818
from typing import Optional
1919
from typing import Union
2020

21-
from django.core.handlers.wsgi import WSGIRequest # type: ignore
22-
from django.http.response import HttpResponse # type: ignore
23-
from django.http.request import QueryDict # type: ignore
24-
from django.utils.datastructures import MultiValueDict # type: ignore
21+
from django.core.handlers.wsgi import WSGIRequest
22+
from django.http.response import HttpResponse
23+
from django.http.request import QueryDict
24+
from django.utils.datastructures import MultiValueDict
2525

2626
from sentry_sdk.integrations.wsgi import _ScopedResponse
2727
from sentry_sdk._types import Event, Hint
2828

2929

3030
try:
31-
from django.urls import resolve # type: ignore
31+
from django.urls import resolve
3232
except ImportError:
33-
from django.core.urlresolvers import resolve # type: ignore
33+
from django.core.urlresolvers import resolve
3434

3535
from sentry_sdk import Hub
3636
from sentry_sdk.hub import _should_send_default_pii
@@ -110,7 +110,7 @@ def sentry_patched_wsgi_handler(self, environ, start_response):
110110

111111
# patch get_response, because at that point we have the Django request
112112
# object
113-
from django.core.handlers.base import BaseHandler # type: ignore
113+
from django.core.handlers.base import BaseHandler
114114

115115
old_get_response = BaseHandler.get_response
116116

@@ -194,7 +194,7 @@ def _django_queryset_repr(value, hint):
194194
# If we fail to import, return `NotImplemen 341A ted`. It's at least
195195
# unlikely that we have a query set in `value` when importing
196196
# `QuerySet` fails.
197-
from django.db.models.query import QuerySet # type: ignore
197+
from django.db.models.query import QuerySet
198198
except Exception:
199199
return NotImplemented
200200

@@ -412,9 +412,9 @@ def install_sql_hook():
412412
# type: () -> None
413413
"""If installed this causes Django's queries to be captured."""
414414
try:
415-
from django.db.backends.utils import CursorWrapper # type: ignore
415+
from django.db.backends.utils import CursorWrapper
416416
except ImportError:
417-
from django.db.backends.util import CursorWrapper # type: ignore
417+
from django.db.backends.util import CursorWrapper
418418

419419
try:
420420
real_execute = CursorWrapper.execute

sentry_sdk/integrations/django/middleware.py

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

55
from functools import wraps
66

7-
from django import VERSION as DJANGO_VERSION # type: ignore
7+
from django import VERSION as DJANGO_VERSION
88

99
from sentry_sdk import Hub
1010
from sentry_sdk.utils import ContextVar, transaction_from_function

sentry_sdk/integrations/django/templates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.template import TemplateSyntaxError # type: ignore
1+
from django.template import TemplateSyntaxError
22

33
from sentry_sdk._types import MYPY
44

@@ -9,10 +9,10 @@
99

1010
try:
1111
# support Django 1.9
12-
from django.template.base import Origin # type: ignore
12+
from django.template.base import Origin
1313
except ImportError:
1414
# backward compatibility
15-
from django.template.loader import LoaderOrigin as Origin # type: ignore
15+
from django.template.loader import LoaderOrigin as Origin
1616

1717

1818
def get_template_frame_from_exception(exc_value):

sentry_sdk/integrations/django/transactions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
from sentry_sdk._types import MYPY
1111

1212
if MYPY:
13-
from django.urls.resolvers import URLResolver # type: ignore
13+
from django.urls.resolvers import URLResolver
1414
from typing import Dict
1515
from typing import List
1616
from typing import Optional
17-
from django.urls.resolvers import URLPattern # type: ignore
17+
from django.urls.resolvers import URLPattern
1818
from typing import Tuple
1919
from typing import Union
2020
from re import Pattern # type: ignore
2121

2222
try:
23-
from django.urls import get_resolver # type: ignore
23+
from django.urls import get_resolver
2424
except ImportError:
25-
from django.core.urlresolvers import get_resolver # type: ignore
25+
from django.core.urlresolvers import get_resolver
2626

2727

2828
def get_regex(resolver_or_pattern):

sentry_sdk/integrations/flask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ def _request_started(sender, **kwargs):
106106
# Rely on WSGI middleware to start a trace
107107
try:
108108
if integration.transaction_style == "endpoint":
109-
scope.transaction = request.url_rule.endpoint # type: ignore
109+
scope.transaction = request.url_rule.endpoint
110110
elif integration.transaction_style == "url":
111-
scope.transaction = request.url_rule.rule # type: ignore
111+
scope.transaction = request.url_rule.rule
112112
except Exception:
113113
pass
114114

0 commit comments

Comments
 (0)
0