Declare backward-compatible method aliases inside class bodies (#797)

* 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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Sean Whalen
2026-06-12 20:50:47 -04:00
committed by GitHub
co-authored by Claude Fable 5
parent ebc6a55715
commit 0c456d44ed
13 changed files with 20 additions and 28 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
__version__ = "10.0.4"
__version__ = "10.1.0"
USER_AGENT = f"parsedmarc/{__version__}"
+2 -3
View File
@@ -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
+3 -4
View File
@@ -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
+2 -3
View File
@@ -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
+2 -3
View File
@@ -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
+2 -3
View File
@@ -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
+2 -5
View File
@@ -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
+1 -1
View File
@@ -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,
)
+1 -1
View File
@@ -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,
)
+1 -1
View File
@@ -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,
)
+1 -1
View File
@@ -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,
)
+1 -1
View File
@@ -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,
)
+1 -1
View File
@@ -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,
)