Skip to content

Commit 7075193

Browse files
committed
chore: Remove __del__ method and tests
1 parent 0819d8b commit 7075193

2 files changed

Lines changed: 0 additions & 54 deletions

File tree

mailjet_rest/client.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -302,21 +302,6 @@ def __exit__(
302302
"""
303303
self.close()
304304

305-
def __del__(self) -> None:
306-
"""Emit a ResourceWarning if the client is garbage collected without being closed (CWE-772)."""
307-
# Ensure session exists and hasn't been closed/cleared already
308-
if hasattr(self, "session") and self.session is not None and self.session.adapters:
309-
warnings.warn(
310-
f"Unclosed Mailjet Client {self!r}. Please use the context manager "
311-
f"(`with Client(...) as client:`) or explicitly call `client.close()`.",
312-
ResourceWarning,
313-
source=self,
314-
stacklevel=2,
315-
)
316-
# Safely attempt to close the lingering session
317-
with suppress(Exception):
318-
self.close()
319-
320305
def __getattr__(self, name: str) -> Endpoint:
321306
"""Dynamically access API endpoints as attributes.
322307

tests/unit/test_client.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -548,45 +548,6 @@ class SimulatedError(Exception):
548548
assert close_called is True, "Exception inside context manager bypassed cleanup!"
549549

550550

551-
def test_client_unclosed_resource_warning() -> None:
552-
"""Verify CWE-772 mitigation: GC on an unclosed client emits a ResourceWarning."""
553-
orphan_client = Client(auth=("test", "test"))
554-
555-
with pytest.warns(ResourceWarning, match="Unclosed Mailjet Client"):
556-
del orphan_client
557-
gc.collect()
558-
559-
def test_client_context_manager_clean_exit() -> None:
560-
"""Verify that using the context manager safely closes the session without warnings."""
561-
with warnings.catch_warnings():
562-
warnings.simplefilter("error", ResourceWarning)
563-
with Client(auth=("test", "test")) as safe_client:
564-
pass # Do nothing
565-
566-
del safe_client
567-
gc.collect()
568-
569-
570-
def test_client_leakage_triggers_resource_warning() -> None:
571-
"""Verify that an unclosed client triggers a ResourceWarning."""
572-
client = Client(auth=("test", "test"))
573-
574-
with pytest.warns(ResourceWarning, match="Please use the context manager"):
575-
del client
576-
gc.collect()
577-
578-
579-
def test_client_cleanup_no_warning() -> None:
580-
"""Verify that an explicitly closed client does NOT trigger a warning."""
581-
with warnings.catch_warnings():
582-
warnings.simplefilter("error", ResourceWarning)
583-
client = Client(auth=("test", "test"))
584-
client.close()
585-
586-
del client
587-
gc.collect()
588-
589-
590551
# ==========================================
591552
# 6. Performance & Memory Optimization Tests
592553
# ==========================================

0 commit comments

Comments
 (0)