From 0c456d44ed1afe8ed8f8dc12673a0a503a68d7c0 Mon Sep 17 00:00:00 2001 From: Sean Whalen <44679+seanthegeek@users.noreply.github.com> Date: Fri, 12 Jun 2026 20:50:47 -0400 Subject: [PATCH] Declare backward-compatible method aliases inside class bodies (#797) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Declare backward-compatible method aliases inside class bodies Assigning the legacy save_forensic_* aliases onto the classes after the class body (KafkaClient.save_forensic_reports_to_kafka = ...) is invisible to static type checkers, so Pylance/Pyright flagged every assignment and every use with reportAttributeAccessIssue. Declaring the alias inside the class body is statically visible — the IDE errors disappear and the aliases get autocomplete and proper typing. Runtime behavior is identical (same function object bound as a method), guarded by the existing assertIs alias tests, whose type-ignore comments are now unnecessary. Also add a pyright ignore on the NoBrokersAvailable import in kafkaclient.py: the import is guarded by try/except ImportError for kafka-python 2.x, but Pyright resolves against the installed 3.x where the name no longer exists. Co-Authored-By: Claude Fable 5 * Bump version to 10.1.0 10.0.4 is tagged and released; CHANGELOG.md already documents the in-progress 10.1.0 section that this release will ship. Co-Authored-By: Claude Fable 5 --------- Co-authored-by: Claude Fable 5 --- parsedmarc/constants.py | 2 +- parsedmarc/gelf.py | 5 ++--- parsedmarc/kafkaclient.py | 7 +++---- parsedmarc/s3.py | 5 ++--- parsedmarc/splunk.py | 5 ++--- parsedmarc/syslog.py | 5 ++--- parsedmarc/webhook.py | 7 ++----- tests/test_gelf.py | 2 +- tests/test_kafkaclient.py | 2 +- tests/test_s3.py | 2 +- tests/test_splunk.py | 2 +- tests/test_syslog.py | 2 +- tests/test_webhook.py | 2 +- 13 files changed, 20 insertions(+), 28 deletions(-) diff --git a/parsedmarc/constants.py b/parsedmarc/constants.py index 97302329..e4afb846 100644 --- a/parsedmarc/constants.py +++ b/parsedmarc/constants.py @@ -1,4 +1,4 @@ -__version__ = "10.0.4" +__version__ = "10.1.0" USER_AGENT = f"parsedmarc/{__version__}" diff --git a/parsedmarc/gelf.py b/parsedmarc/gelf.py index a0dfd938..374a8bc2 100644 --- a/parsedmarc/gelf.py +++ b/parsedmarc/gelf.py @@ -76,6 +76,5 @@ class GelfClient(object): self.logger.removeHandler(self.handler) self.handler.close() - -# Backward-compatible aliases -GelfClient.save_forensic_report_to_gelf = GelfClient.save_failure_report_to_gelf + # Backward-compatible alias + save_forensic_report_to_gelf = save_failure_report_to_gelf diff --git a/parsedmarc/kafkaclient.py b/parsedmarc/kafkaclient.py index 9ec84d38..2b8cf048 100644 --- a/parsedmarc/kafkaclient.py +++ b/parsedmarc/kafkaclient.py @@ -11,7 +11,7 @@ from kafka.errors import UnknownTopicOrPartitionError try: # kafka-python < 3.0 raises this when the producer cannot bootstrap - from kafka.errors import NoBrokersAvailable as _BootstrapError + from kafka.errors import NoBrokersAvailable as _BootstrapError # pyright: ignore[reportAttributeAccessIssue] except ImportError: # kafka-python >= 3.0 removed NoBrokersAvailable; a failed bootstrap # raises KafkaTimeoutError instead @@ -219,6 +219,5 @@ class KafkaClient(object): except Exception as e: raise KafkaError("Kafka error: {0}".format(e.__str__())) - -# Backward-compatible aliases -KafkaClient.save_forensic_reports_to_kafka = KafkaClient.save_failure_reports_to_kafka + # Backward-compatible alias + save_forensic_reports_to_kafka = save_failure_reports_to_kafka diff --git a/parsedmarc/s3.py b/parsedmarc/s3.py index 226f5d19..01827b6d 100644 --- a/parsedmarc/s3.py +++ b/parsedmarc/s3.py @@ -115,6 +115,5 @@ class S3Client(object): except Exception: pass - -# Backward-compatible aliases -S3Client.save_forensic_report_to_s3 = S3Client.save_failure_report_to_s3 + # Backward-compatible alias + save_forensic_report_to_s3 = save_failure_report_to_s3 diff --git a/parsedmarc/splunk.py b/parsedmarc/splunk.py index eaffad86..a1aa6acd 100644 --- a/parsedmarc/splunk.py +++ b/parsedmarc/splunk.py @@ -221,6 +221,5 @@ class HECClient(object): """Close the underlying HTTP session.""" self.session.close() - -# Backward-compatible aliases -HECClient.save_forensic_reports_to_splunk = HECClient.save_failure_reports_to_splunk + # Backward-compatible alias + save_forensic_reports_to_splunk = save_failure_reports_to_splunk diff --git a/parsedmarc/syslog.py b/parsedmarc/syslog.py index 883987ab..7862797b 100644 --- a/parsedmarc/syslog.py +++ b/parsedmarc/syslog.py @@ -185,6 +185,5 @@ class SyslogClient(object): self.logger.removeHandler(self.log_handler) self.log_handler.close() - -# Backward-compatible aliases -SyslogClient.save_forensic_report_to_syslog = SyslogClient.save_failure_report_to_syslog + # Backward-compatible alias + save_forensic_report_to_syslog = save_failure_report_to_syslog diff --git a/parsedmarc/webhook.py b/parsedmarc/webhook.py index 0d543ad6..7d2dfc8e 100644 --- a/parsedmarc/webhook.py +++ b/parsedmarc/webhook.py @@ -64,8 +64,5 @@ class WebhookClient(object): """Close the underlying HTTP session.""" self.session.close() - -# Backward-compatible aliases -WebhookClient.save_forensic_report_to_webhook = ( - WebhookClient.save_failure_report_to_webhook -) + # Backward-compatible alias + save_forensic_report_to_webhook = save_failure_report_to_webhook diff --git a/tests/test_gelf.py b/tests/test_gelf.py index 23781815..6974f160 100644 --- a/tests/test_gelf.py +++ b/tests/test_gelf.py @@ -325,7 +325,7 @@ class TestGelfClientClose(unittest.TestCase): class TestGelfClientBackwardCompatAlias(unittest.TestCase): def test_forensic_alias_points_to_failure_method(self): self.assertIs( - GelfClient.save_forensic_report_to_gelf, # type: ignore[attr-defined] + GelfClient.save_forensic_report_to_gelf, GelfClient.save_failure_report_to_gelf, ) diff --git a/tests/test_kafkaclient.py b/tests/test_kafkaclient.py index 82b4dcaf..2c4a673c 100644 --- a/tests/test_kafkaclient.py +++ b/tests/test_kafkaclient.py @@ -271,7 +271,7 @@ class TestKafkaClientClose(unittest.TestCase): class TestKafkaBackwardCompatAlias(unittest.TestCase): def test_forensic_alias_points_to_failure_method(self): self.assertIs( - KafkaClient.save_forensic_reports_to_kafka, # type: ignore[attr-defined] + KafkaClient.save_forensic_reports_to_kafka, KafkaClient.save_failure_reports_to_kafka, ) diff --git a/tests/test_s3.py b/tests/test_s3.py index 889853c7..10a5305f 100644 --- a/tests/test_s3.py +++ b/tests/test_s3.py @@ -211,7 +211,7 @@ class TestS3ClientClose(unittest.TestCase): class TestS3ClientBackwardCompatAlias(unittest.TestCase): def test_forensic_alias_points_to_failure_method(self): self.assertIs( - S3Client.save_forensic_report_to_s3, # type: ignore[attr-defined] + S3Client.save_forensic_report_to_s3, S3Client.save_failure_report_to_s3, ) diff --git a/tests/test_splunk.py b/tests/test_splunk.py index e6881d23..6a714e8d 100644 --- a/tests/test_splunk.py +++ b/tests/test_splunk.py @@ -420,7 +420,7 @@ class TestHECClientClose(unittest.TestCase): class TestSplunkBackwardCompatAlias(unittest.TestCase): def test_forensic_alias_points_to_failure_method(self): self.assertIs( - HECClient.save_forensic_reports_to_splunk, # type: ignore[attr-defined] + HECClient.save_forensic_reports_to_splunk, HECClient.save_failure_reports_to_splunk, ) diff --git a/tests/test_syslog.py b/tests/test_syslog.py index 7aafa5b1..33c9dd7a 100644 --- a/tests/test_syslog.py +++ b/tests/test_syslog.py @@ -356,7 +356,7 @@ class TestSyslogClientClose(unittest.TestCase): class TestSyslogBackwardCompatAlias(unittest.TestCase): def test_forensic_alias_points_to_failure_method(self): self.assertIs( - SyslogClient.save_forensic_report_to_syslog, # type: ignore[attr-defined] + SyslogClient.save_forensic_report_to_syslog, SyslogClient.save_failure_report_to_syslog, ) diff --git a/tests/test_webhook.py b/tests/test_webhook.py index 2a814473..489af50d 100644 --- a/tests/test_webhook.py +++ b/tests/test_webhook.py @@ -112,7 +112,7 @@ class TestWebhookClientClose(unittest.TestCase): class TestWebhookBackwardCompatAlias(unittest.TestCase): def test_forensic_alias_points_to_failure_method(self): self.assertIs( - WebhookClient.save_forensic_report_to_webhook, # type: ignore[attr-defined] + WebhookClient.save_forensic_report_to_webhook, WebhookClient.save_failure_report_to_webhook, )