Skip to content

Commit b6db74e

Browse files
committed
chore: add tests/wire/__init__.py to fernignore
Document the Python 3.8-3.10 datetime.fromisoformat compatibility fix that patches datetime.datetime.fromisoformat() to handle 'Z' suffix in ISO 8601 strings. This allows generated wire test files to work across all supported Python versions without modification.
1 parent f8a656a commit b6db74e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

.fernignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ tests/wire/test_listen_v1_media.py
1616
tests/wire/test_speak_v1_audio.py
1717
tests/wire/conftest.py
1818

19+
# Wire tests __init__.py with Python 3.8-3.10 datetime.fromisoformat compatibility fix:
20+
# The Fern generator creates test files that use datetime.fromisoformat() with ISO 8601 strings
21+
# ending in 'Z' (e.g., '2024-01-15T09:30:00Z'). However, Python 3.10's datetime.fromisoformat()
22+
# doesn't support the 'Z' suffix (this was added in Python 3.11). Python 3.8 and 3.9 also lack
23+
# this support.
24+
#
25+
# Rather than modifying generated test files (which would be overwritten on regeneration), we
26+
# implement a monkey-patch in tests/wire/__init__.py that wraps the datetime.datetime class
27+
# and overrides fromisoformat() to automatically convert 'Z' to '+00:00' before calling the
28+
# original implementation.
29+
#
30+
# This ensures:
31+
# 1. Generated test files remain unchanged and can be regenerated without conflicts
32+
# 2. All wire tests pass on Python 3.8, 3.9, and 3.10 (as well as 3.11+)
33+
# 3. The fix is transparent to all code importing datetime.datetime in the wire tests module
34+
#
35+
# The implementation uses a wrapper class that inherits from the original datetime class,
36+
# ensuring all other datetime functionality remains unchanged. The wrapper is injected into
37+
# sys.modules['datetime'].datetime so that any 'from datetime import datetime' statements
38+
# in the wire tests will get the patched version.
39+
tests/wire/__init__.py
40+
1941
# Manual standalone tests
2042
tests/manual
2143

0 commit comments

Comments
 (0)