Skip to content

Conversation

@cjw296
Copy link
Owner

@cjw296 cjw296 commented Jul 3, 2025

Summary

  • refactor typing imports in datetime.py
  • define DateTimeKwargs, DateTimeArgs, DateKwargs, DateArgs, TimeKwargs, and TimeArgs

Testing

  • mypy testfixtures
  • pytest -q

https://chatgpt.com/codex/tasks/task_e_686619391a4c83218617b70506e766f6

cjw296 and others added 30 commits July 2, 2025 18:48
…astructure

- Add basic Queue, MockedCurrent, and MockDateTime classes with modern typing
- Implement minimal mock_datetime() factory function
- First test_now passes with proper mypy compliance
- Export mock_datetime from testfixtures.__init__.py

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…one support

- Add timezone helper classes (SampleTZInfo, SampleTZInfo2, WeirdTZInfo) with proper typing
- Implement timezone offset handling in MockDateTime.now() method
- Second test passes: datetime.now(tz) correctly applies timezone offset
- Both tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for mock_datetime(tzinfo=SampleTZInfo()) configuration
- Test passes with existing timezone handling in MockDateTime.now()
- All three tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add _adjust_instance_using_tzinfo method to handle mock's configured timezone
- Implement proper error handling for timezone with None utcoffset
- Test correctly raises TypeError when calling now(tz=...) on mock with WeirdTZInfo
- All four tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Simplify mock_factory to use cls.add(*args, **kw) like the original
- Implement basic add() method in MockedCurrent class
- Remove complex manual datetime construction logic
- All existing tests still pass with cleaner, more maintainable code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for mixed timezone scenarios: mock configured with one timezone, now() called with different timezone
- Test passes with existing timezone handling logic
- All five tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for timezone scenario where mock and now() call use same timezone
- Test passes with existing timezone handling logic (adjustments cancel out)
- All six tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…zone extraction

- Add support for passing datetime instances with timezone to mock_datetime()
- Implement timezone extraction and datetime timezone stripping in add() method
- Mock extracts tzinfo and stores timezone-naive datetime in queue
- All seven tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test combining timezone instance creation with supplied timezone to now() call
- Test passes with existing timezone handling logic
- All eight tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…plied)

- Add test for timezone instance creation with same timezone supplied to now()
- Test passes with existing timezone handling logic
- All nine tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for mock_datetime with explicit datetime parameters (2002, 1, 1, 1, 2, 3)
- Test passes with existing parameter handling in mock_factory
- All ten tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for mock_datetime(None) with manual add() calls to build sequence
- Import MockDateTime for type annotations
- Test passes with existing add() method and queue handling
- All eleven tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add set() method to MockedCurrent class that clears queue and adds new datetime
- Test validates set() clears previous add() calls and starts new progression
- All twelve tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…timezone validation

- Add timezone compatibility check in add() method
- Validate that added datetime's tzinfo matches mock's configured tzinfo
- Raise ValueError with descriptive message for tzinfo mismatches
- All thirteen tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for passing datetime instance directly to mock_datetime()
- Test passes with existing datetime instance handling
- All fourteen tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…plied)

- Add test for automatic delta progression when queue is exhausted
- Test validates Queue.next() automatically generates new values with delta increments
- All fifteen tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
… strict mode

- Add __new__ method to MockedCurrent for constructor behavior control
- When strict=True, mock class constructor returns mock instances
- When strict=False, returns base datetime class instances
- All sixteen tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…() method

- Add date() method to MockDateTime that returns proper date type
- Initialize _mock_date_type with proper default handling
- Test validates datetime.date() returns correct date class instance
- All seventeen tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for manual replacer usage with mock datetime instances
- Import sample1 module for test dependencies
- Test passes with existing mock functionality
- All eighteen tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for mock class repr() representation
- Test validates replaced datetime class shows MockDateTime name
- All nineteen tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for custom delta=1 parameter (1 second increments)
- Test validates delta progression: 0, 1, 2 seconds
- All twenty tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for delta_type='minutes' parameter
- Test validates minute-based progression: 0, 10, 30 minutes
- All twenty-one tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for set() method with mock_datetime(None)
- Fix mypy error by using separate variable for cast instead of reassigning datetime
- Test validates set() clears queue and establishes new progression
- All twenty-two tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for set() method with datetime instances and timezone validation
- Test validates set() accepts datetime instances and enforces timezone constraints
- All twenty-three tests pass with full mypy compliance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
… modern typing

Fixed add() method to properly handle keyword arguments (year=, month=, day=)
when creating datetime instances. Uses type-safe checks to ensure kwargs are
int before using them for datetime construction.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Test verifies that set() method works properly with keyword arguments only.
Uses modern type annotations with proper return type annotation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…typing

Implemented validation to raise TypeError when tzinfo is passed as keyword
argument to add() or set() methods, maintaining API compatibility with
original implementation. Uses modern type annotations.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
cjw296 and others added 25 commits July 2, 2025 18:50
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…rgs for MockTime

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…test_kw_tzinfo for MockTime

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…mport

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Queue[T] where T is bound to datetime  < /dev/null |  date
- MockDateTime uses Queue[datetime]
- MockDate uses Queue[date]
- MockTime uses Queue[datetime]
- Removed cast() calls from now(), utcnow(), today(), and MockTime.__new__()
- Uses modern Python 3.11+ syntax with TypeVar bound to union type

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- MockedCurrent[T] where T is bound to datetime  < /dev/null |  date
- MockDateTime extends MockedCurrent[datetime]
- MockDate extends MockedCurrent[date]
- MockTime extends MockedCurrent[datetime]
- Updated mock_factory to be generic
- Removed 5 type: ignore comments by improving type annotations
- Improved _correct_mock_type methods with better casting

Note: One test_isinstance_strict test currently failing - needs strict mode fix

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Prefer type-ignores instead
The return type annotation in MockedCurrent.__add__ method no longer
needs a type ignore comment as the generic type constraints properly
handle the return value.

Reduced type ignore count from 18 to 17 without introducing any casts
or changing the external API.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@cjw296 cjw296 force-pushed the datetime-reimplement branch 4 times, most recently from 1157e2c to f443e5a Compare July 3, 2025 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants