Browse Source

ref: add minimal stubs for ua_parser (#62280)

<!-- Describe your PR here. -->
anthony sottile 1 year ago
parent
commit
8df8f1e36c

+ 0 - 0
fixtures/stubs-for-mypy/ua_parser/__init__.pyi


+ 27 - 0
fixtures/stubs-for-mypy/ua_parser/user_agent_parser.pyi

@@ -0,0 +1,27 @@
+from typing import TypedDict
+
+class _ParseUserAgentResult(TypedDict):
+    family: str
+    major: str | None
+    minor: str | None
+    patch: str | None
+
+class _ParseOsResult(TypedDict):
+    family: str
+    major: str | None
+    minor: str | None
+    patch: str | None
+    patch_minor: str | None
+
+class _ParseDeviceResult(TypedDict):
+    family: str
+    brand: str | None
+    model: str | None
+
+class _ParseResult(TypedDict):
+    user_agent: _ParseUserAgentResult
+    os: _ParseOsResult
+    device: _ParseDeviceResult
+    string: str
+
+def Parse(user_agent_string: str) -> _ParseResult: ...

+ 0 - 1
pyproject.toml

@@ -116,7 +116,6 @@ module = [
     "sqlparse.*",
     "statsd.*",
     "u2flib_server.model.*",
-    "ua_parser.user_agent_parser.*",
     "unidiff.*",
 ]
 ignore_missing_imports = true

+ 1 - 4
src/sentry/plugins/sentry_useragents/models.py

@@ -31,10 +31,7 @@ class UserAgentPlugin(TagPlugin):
         for key, value in headers:
             if key != "User-Agent":
                 continue
-            ua = Parse(value)
-            if not ua:
-                continue
-            result = self.get_tag_from_ua(ua)
+            result = self.get_tag_from_ua(Parse(value))
             if result:
                 output.append(result)
         return output