Browse Source

ref: upgrade to mypy 0.9xx (#37608)

anthony sottile 2 years ago
parent
commit
cc82be15ce

+ 2 - 0
mypy.ini

@@ -115,6 +115,8 @@ files = src/sentry/analytics/,
         tests/sentry/utils/appleconnect/,
         tools/
 
+show_error_codes = true
+
 ; Enable all options used with --strict
 warn_unused_configs=True
 disallow_any_generics=True

+ 7 - 2
requirements-dev-frozen.txt

@@ -78,7 +78,7 @@ mock==4.0.3
 more-itertools==8.13.0
 msgpack==1.0.4
 msgpack-types==0.2.0
-mypy==0.812
+mypy==0.971
 mypy-extensions==0.4.3
 natsort==8.1.0
 nodeenv==1.6.0
@@ -161,7 +161,12 @@ tomli==2.0.1
 toronado==0.1.0
 trio==0.21.0
 trio-websocket==0.9.2
-typed-ast==1.4.3
+types-freezegun==1.1.10
+types-python-dateutil==2.8.19
+types-pytz==2022.1.2
+types-redis==4.3.13
+types-requests==2.28.8
+types-urllib3==1.26.22
 typing-extensions==3.10.0.2
 typing-inspect==0.7.1
 ua-parser==0.10.0

+ 7 - 2
requirements-dev-only-frozen.txt

@@ -31,7 +31,7 @@ mccabe==0.7.0
 mock==4.0.3
 more-itertools==8.13.0
 msgpack-types==0.2.0
-mypy==0.812
+mypy==0.971
 mypy-extensions==0.4.3
 nodeenv==1.6.0
 openapi-core==0.14.2
@@ -67,7 +67,12 @@ six==1.16.0
 tokenize-rt==4.2.1
 toml==0.10.2
 tomli==2.0.1
-typed-ast==1.4.3
+types-freezegun==1.1.10
+types-python-dateutil==2.8.19
+types-pytz==2022.1.2
+types-redis==4.3.13
+types-requests==2.28.8
+types-urllib3==1.26.22
 typing-extensions==4.2.0
 urllib3==1.26.9
 virtualenv==20.14.1

+ 9 - 2
requirements-dev.txt

@@ -2,7 +2,6 @@ docker>=3.7.0,<3.8.0
 exam>=0.10.6
 freezegun>=1.1.0
 honcho>=1.0.0,<1.1.0
-mypy>=0.800,<0.900
 openapi-core>=0.14.2
 pytest>=6.1.0
 pytest-cov>=3.0.0
@@ -11,7 +10,6 @@ pytest-rerunfailures>=9.1.1
 pytest-sentry>=0.1.9
 pytest-xdist
 responses>=0.21.0
-msgpack-types>=0.2.0
 
 # pre-commit dependencies
 pre-commit>=2.18.1
@@ -25,3 +23,12 @@ isort>=5.10.1
 # note: wheel is pulled in by pip-tools
 pip-tools>=6.7.0
 packaging>=21.3
+
+# for type checking
+msgpack-types>=0.2.0
+mypy>=0.971
+types-freezegun
+types-python-dateutil
+types-pytz
+types-redis
+types-requests

+ 1 - 1
src/sentry/analytics/event.py

@@ -27,7 +27,7 @@ class Event:
     ) -> None:
         self.uuid = uuid1()
         self.datetime = datetime or timezone.now()
-        self.type = self._get_type(type)
+        self.type = self._get_type(type)  # type: ignore[misc]
         self.data = get_data(self.attributes, items)
 
     def _get_type(self, _type: Any | None = None) -> Any:

+ 1 - 1
src/sentry/api/endpoints/organization_events_trace.py

@@ -362,7 +362,7 @@ class OrganizationEventsTraceEndpointBase(OrganizationEventsV2EndpointBase):  #
             sentry_sdk.set_tag("discover.trace-view.warning", "root.extra-found")
             logger.warning(
                 "discover.trace-view.root.extra-found",
-                {"extra_roots": len(roots), **warning_extra},
+                extra={"extra_roots": len(roots), **warning_extra},
             )
 
         return Response(

+ 2 - 2
src/sentry/constants.py

@@ -7,7 +7,7 @@ import logging
 import os.path
 from collections import OrderedDict, namedtuple
 from datetime import timedelta
-from typing import Dict, List, Optional, Sequence, Tuple
+from typing import Dict, List, Optional, Sequence, Tuple, cast
 
 import sentry_relay
 from django.conf import settings
@@ -29,7 +29,7 @@ def get_all_languages() -> List[str]:
     return results
 
 
-MODULE_ROOT = os.path.dirname(__import__("sentry").__file__)
+MODULE_ROOT = os.path.dirname(cast(str, __import__("sentry").__file__))
 DATA_ROOT = os.path.join(MODULE_ROOT, "data")
 
 BAD_RELEASE_CHARS = "\r\n\f\x0c\t/\\"

+ 1 - 1
src/sentry/killswitches.py

@@ -69,7 +69,7 @@ class KillswitchCallback:
     title: str
 
     def __call__(self, old: Any, new: Any) -> None:
-        self.callback(old, new)  # type: ignore
+        self.callback(old, new)
 
 
 @dataclass

+ 1 - 2
src/sentry/ratelimits/utils.py

@@ -72,8 +72,7 @@ def get_rate_limit_key(
     if isinstance(request_auth, SystemToken):
         return None
 
-    if isinstance(request_auth, ApiToken):
-
+    if isinstance(request_auth, ApiToken) and request_user:
         if request_user.is_sentry_app:
             category = "org"
             id = get_organization_id_from_token(request_auth.id)

+ 1 - 2
src/sentry/sentry_metrics/metrics_wrapper.py

@@ -1,4 +1,3 @@
-from collections import ChainMap
 from typing import Mapping, Optional, Union
 
 from sentry.metrics.base import MetricsBackend
@@ -29,7 +28,7 @@ class MetricsWrapper(MetricsBackend):  # type: ignore
         elif tags is None:
             return self.__tags
         else:
-            return ChainMap(tags, self.__tags)
+            return {**self.__tags, **tags}
 
     def increment(
         self, name: str, value: Union[int, float] = 1, tags: Optional[Tags] = None

Some files were not shown because too many files changed in this diff