From 7a2ed797593bd293d3103378cb8a6a1e7618c643 Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Fri, 28 Aug 2026 14:23:58 -0400 Subject: [PATCH] fix: remove dead-code Python version guard in utils/__init__.py (#270) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The guard: if sys.version_info.major == 3 and sys.version_info.minor >= 3: from collections.abc import MutableMapping else: from collections.abc import MutableMapping has identical branches — both import from collections.abc (the correct Python 3.3+ location). Remove the guard; keep the bare import. Closes #251 --- ChangeLog.md | 2 ++ aprsd/utils/__init__.py | 6 +----- tests/utils/test_utils.py | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index c6612e6..f57cc18 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -12,6 +12,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - Enable ruff isort (I) ruleset in pyproject.toml [`a3801f6`](https://github.com/craigerl/aprsd/commit/a3801f6) +- Remove dead-code Python version guard in utils/__init__.py: both branches were identical [`aa43f60`](https://github.com/craigerl/aprsd/commit/aa43f60) + - Add reset() to @singleton decorator; update tests to use ClassName.reset() instead of ClassName.instance = None [`ef19aaa`](https://github.com/craigerl/aprsd/commit/ef19aaa) - Fix PacketTrack.keys/items/values — return list snapshots instead of live dict views outside the lock [`088436e`](https://github.com/craigerl/aprsd/commit/088436e) diff --git a/aprsd/utils/__init__.py b/aprsd/utils/__init__.py index 17f9bcd..31cc18b 100644 --- a/aprsd/utils/__init__.py +++ b/aprsd/utils/__init__.py @@ -7,6 +7,7 @@ import os import re import sys import traceback +from collections.abc import MutableMapping import update_checker @@ -18,11 +19,6 @@ from .fuzzyclock import fuzzy # noqa: F401 # aprsd.utils from .ring_buffer import RingBuffer # noqa: F401 -if sys.version_info.major == 3 and sys.version_info.minor >= 3: - from collections.abc import MutableMapping -else: - from collections.abc import MutableMapping - def singleton(cls): """Make a class a Singleton class (only one instance). diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index 94f9137..de836f9 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -323,3 +323,22 @@ class TestUtils(unittest.TestCase): level, msg = utils._check_version() self.assertEqual(level, 1) self.assertEqual(msg, 'New version available') + + +class TestDeadCodeRemoval(unittest.TestCase): + """Regression tests for dead code that was removed.""" + + def test_mutable_mapping_importable(self): + """MutableMapping must be importable from aprsd.utils after dead-code removal. + + The version guard + if sys.version_info.major == 3 and sys.version_info.minor >= 3: + from collections.abc import MutableMapping + else: + from collections.abc import MutableMapping + had both branches do the same thing. After removing the guard the import + must still succeed on all supported Python versions. + """ + from aprsd.utils import MutableMapping as MM # noqa: N814 + + self.assertTrue(issubclass(dict, MM))