Browse Source

ref: clean up remaining pytz remnants (#84466)

<!-- Describe your PR here. -->
anthony sottile 1 month ago
parent
commit
8864d7177b

+ 0 - 1
requirements-dev-frozen.txt

@@ -225,7 +225,6 @@ types-protobuf==4.23.0.1
 types-psutil==5.9.5.16
 types-psycopg2==2.9.21
 types-python-dateutil==2.8.19
-types-pytz==2022.1.2
 types-pyyaml==6.0.11
 types-redis==3.5.18
 types-requests==2.32.0.20241016

+ 0 - 1
requirements-dev.txt

@@ -53,7 +53,6 @@ types-protobuf
 types-psutil
 types-psycopg2
 types-python-dateutil
-types-pytz
 types-pyyaml
 # make sure to match close-enough to redis==
 types-redis<4

+ 6 - 0
tests/sentry/test_dependencies.py

@@ -1,4 +1,5 @@
 import pydantic
+import pytest
 
 
 def test_pydantic_1x_compiled() -> None:
@@ -6,3 +7,8 @@ def test_pydantic_1x_compiled() -> None:
         raise AssertionError("delete this test, it only applies to pydantic 1.x")
     # pydantic is horribly slow when not cythonized
     assert pydantic.__file__.endswith(".so")
+
+
+def test_pytz_is_not_installed() -> None:
+    with pytest.raises(ImportError):
+        __import__("pytz")  # do not allow this to creep in.  use zoneinfo

+ 0 - 16
tests/tools/test_flake8_plugin.py

@@ -2,8 +2,6 @@ from __future__ import annotations
 
 import ast
 
-import pytest
-
 from tools.flake8_plugin import SentryCheck
 
 
@@ -135,20 +133,6 @@ import sentry.testutils.outbox as outbox_utils
     ]
 
 
-@pytest.mark.parametrize(
-    "src",
-    (
-        "from pytz import utc",
-        "from pytz import UTC",
-        "pytz.utc",
-        "pytz.UTC",
-    ),
-)
-def test_S008(src):
-    expected = ["t.py:1:0: S008 Use stdlib datetime.timezone.utc instead of pytz.utc / pytz.UTC"]
-    assert _run(src) == expected
-
-
 def test_S009():
     src = """\
 try:

+ 0 - 11
tools/flake8_plugin.py

@@ -25,8 +25,6 @@ S006_msg = "S006 Do not use force_bytes / force_str -- test the types directly"
 
 S007_msg = "S007 Do not import sentry.testutils into production code."
 
-S008_msg = "S008 Use stdlib datetime.timezone.utc instead of pytz.utc / pytz.UTC"
-
 S009_msg = "S009 Use `raise` with no arguments to reraise exceptions"
 
 S010_msg = "S010 Except handler does nothing and should be removed"
@@ -61,9 +59,6 @@ class SentryVisitor(ast.NodeVisitor):
             ):
                 self.errors.append((node.lineno, node.col_offset, S007_msg))
 
-            if node.module == "pytz" and any(x.name.lower() == "utc" for x in node.names):
-                self.errors.append((node.lineno, node.col_offset, S008_msg))
-
         self.generic_visit(node)
 
     def visit_Import(self, node: ast.Import) -> None:
@@ -85,12 +80,6 @@ class SentryVisitor(ast.NodeVisitor):
             self.errors.append((node.lineno, node.col_offset, S001_fmt.format(node.attr)))
         elif node.attr in S004_methods:
             self.errors.append((node.lineno, node.col_offset, S004_msg))
-        elif (
-            isinstance(node.value, ast.Name)
-            and node.value.id == "pytz"
-            and node.attr.lower() == "utc"
-        ):
-            self.errors.append((node.lineno, node.col_offset, S008_msg))
 
         self.generic_visit(node)