Skip to content

Commit

Permalink
ref: Remove all exemptions from mypy.ini (#516)
Browse files Browse the repository at this point in the history
* ref: Remove all exemptions from mypy.ini

* fix: Revert buggy logic
  • Loading branch information
untitaker authored Sep 27, 2019
1 parent 3551b98 commit f763061
Show file tree
Hide file tree
Showing 30 changed files with 390 additions and 212 deletions.
108 changes: 1 addition & 107 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ check_untyped_defs = True
disallow_any_generics = True
; disallow_any_unimported = True
disallow_incomplete_defs = True
; disallow_subclassing_any = True
disallow_subclassing_any = True
; disallow_untyped_calls = True
disallow_untyped_decorators = True
disallow_untyped_defs = True
Expand All @@ -26,112 +26,6 @@ warn_unused_ignores = True
; Do not use wildcards in module paths, otherwise added modules will
; automatically have the same set of relaxed rules as the rest

[mypy-sentry_sdk._compat]
disallow_untyped_defs = False

[mypy-sentry_sdk.scope]
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.django]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.django.middleware]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.bottle]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.flask]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.asgi]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.falcon]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.aws_lambda]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.pyramid]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.celery]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.beam]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.sanic]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.tornado]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.atexit]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations._wsgi_common]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.wsgi]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.serverless]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.excepthook]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.threading]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.stdlib]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.sqlalchemy]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.rq]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.redis]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.gnu_backtrace]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.integrations.django.templates]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-sentry_sdk.utils]
disallow_any_generics = False
disallow_untyped_defs = False

[mypy-django.*]
ignore_missing_imports = True
[mypy-pyramid.*]
Expand Down
11 changes: 8 additions & 3 deletions sentry_sdk/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from typing import Any
from typing import Type

from typing import TypeVar

T = TypeVar("T")


PY2 = sys.version_info[0] == 2

Expand All @@ -23,6 +27,7 @@
iteritems = lambda x: x.iteritems() # noqa: B301

def implements_str(cls):
# type: (T) -> T
cls.__unicode__ = cls.__str__
cls.__str__ = lambda x: unicode(x).encode("utf-8") # noqa
return cls
Expand All @@ -40,10 +45,8 @@ def implements_str(cls):
int_types = (int,) # noqa
iteritems = lambda x: x.items()

def _identity(x):
return x

def implements_str(x):
# type: (T) -> T
return x

def reraise(tp, value, tb=None):
Expand All @@ -55,8 +58,10 @@ def reraise(tp, value, tb=None):


def with_metaclass(meta, *bases):
# type: (Any, *Any) -> Any
class metaclass(type):
def __new__(cls, name, this_bases, d):
# type: (Any, Any, Any, Any) -> Any
return meta(name, bases, d)

return type.__new__(metaclass, "temporary_class", (), {})
Expand Down
3 changes: 3 additions & 0 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@
EventProcessor = Callable[[Event, Hint], Optional[Event]]
ErrorProcessor = Callable[[Event, ExcInfo], Optional[Event]]
BreadcrumbProcessor = Callable[[Breadcrumb, BreadcrumbHint], Optional[Breadcrumb]]

# https://github.com/python/mypy/issues/5710
NotImplementedType = Any
22 changes: 17 additions & 5 deletions sentry_sdk/integrations/_wsgi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ def content_length(self):
return 0

def cookies(self):
# type: () -> Dict[str, Any]
raise NotImplementedError()

def raw_data(self):
# type: () -> Optional[Union[str, bytes]]
raise NotImplementedError()

def form(self):
# type: () -> Optional[Dict[str, Any]]
raise NotImplementedError()

def parsed_body(self):
Expand All @@ -110,28 +113,37 @@ def is_json(self):
def json(self):
# type: () -> Optional[Any]
try:
if self.is_json():
raw_data = self.raw_data()
if not isinstance(raw_data, text_type):
raw_data = raw_data.decode("utf-8")
if not self.is_json():
return None

raw_data = self.raw_data()
if raw_data is None:
return None

if isinstance(raw_data, text_type):
return json.loads(raw_data)
else:
return json.loads(raw_data.decode("utf-8"))
except ValueError:
pass

return None

def files(self):
# type: () -> Optional[Dict[str, Any]]
raise NotImplementedError()

def size_of_file(self, file):
# type: (Any) -> int
raise NotImplementedError()

def env(self):
# type: () -> Dict[str, Any]
raise NotImplementedError()


def _is_json_content_type(ct):
# type: (str) -> bool
# type: (Optional[str]) -> bool
mt = (ct or "").split(";", 1)[0]
return (
mt == "application/json"
Expand Down
12 changes: 12 additions & 0 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
if MYPY:
from typing import Dict
from typing import Any
from typing import Optional

from sentry_sdk._types import Event, Hint


_asgi_middleware_applied = ContextVar("sentry_asgi_middleware_applied")
Expand All @@ -38,12 +41,15 @@ class SentryAsgiMiddleware:
__slots__ = ("app",)

def __init__(self, app):
# type: (Any) -> None
self.app = app

def __call__(self, scope, receive=None, send=None):
# type: (Any, Any, Any) -> Any
if receive is None or send is None:

async def run_asgi2(receive, send):
# type: (Any, Any) -> Any
return await self._run_app(
scope, lambda: self.app(scope)(receive, send)
)
Expand All @@ -53,6 +59,7 @@ async def run_asgi2(receive, send):
return self._run_app(scope, lambda: self.app(scope, receive, send))

async def _run_app(self, scope, callback):
# type: (Any, Any) -> Any
if _asgi_middleware_applied.get(False):
return await callback()

Expand Down Expand Up @@ -88,6 +95,7 @@ async def _run_app(self, scope, callback):
_asgi_middleware_applied.set(False)

def event_processor(self, event, hint, asgi_scope):
# type: (Event, Hint, Any) -> Optional[Event]
request_info = event.setdefault("request", {})

if asgi_scope["type"] in ("http", "websocket"):
Expand All @@ -107,6 +115,7 @@ def event_processor(self, event, hint, asgi_scope):
return event

def get_url(self, scope):
# type: (Any) -> str
"""
Extract URL from the ASGI scope, without also including the querystring.
"""
Expand All @@ -128,12 +137,14 @@ def get_url(self, scope):
return path

def get_query(self, scope):
# type: (Any) -> Any
"""
Extract querystring from the ASGI scope, in the format that the Sentry protocol expects.
"""
return urllib.parse.unquote(scope["query_string"].decode("latin-1"))

def get_headers(self, scope):
# type: (Any) -> Dict[str, Any]
"""
Extract headers from the ASGI scope, in the format that the Sentry protocol expects.
"""
Expand All @@ -148,6 +159,7 @@ def get_headers(self, scope):
return headers

def get_transaction(self, scope):
# type: (Any) -> Optional[str]
"""
Return a transaction string to identify the routed endpoint.
"""
Expand Down
2 changes: 2 additions & 0 deletions sentry_sdk/integrations/atexit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


def default_callback(pending, timeout):
# type: (int, int) -> None
"""This is the default shutdown callback that is set on the options.
It prints out a message to stderr that informs the user that some events
are still pending and the process is waiting for them to flush out.
Expand Down Expand Up @@ -46,6 +47,7 @@ def setup_once():
# type: () -> None
@atexit.register
def _shutdown():
# type: () -> None
logger.debug("atexit: got shutdown signal")
hub = Hub.main
integration = hub.get_integration(AtexitIntegration)
Expand Down
Loading

0 comments on commit f763061

Please sign in to comment.