Skip to content

Fix datetime.datetime not supporting __class_getitem__ in runtime context#29

Draft
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-datetime-class-getitem-issue
Draft

Fix datetime.datetime not supporting __class_getitem__ in runtime context#29
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-datetime-class-getitem-issue

Conversation

Copy link
Copy Markdown

Copilot AI commented Dec 20, 2025

Plan: Add class_getitem support to datetime class

  • Explore repository and understand the issue
  • Identify that only datetime.datetime class needs class_getitem
  • Add class_getitem to datetime.datetime (C implementation)
  • Add class_getitem to datetime.datetime (pure Python implementation)
  • Build and manually test the changes
  • Create tests for the new functionality
  • Run existing tests to ensure no breakage
  • Run code review
  • Run CodeQL security check
  • Add documentation for the new feature
  • Update examples and tests to use tzinfo instead of int

Summary

This PR adds __class_getitem__ support to the datetime.datetime class only, as requested. This enables the datetime class to be used with generic type syntax at runtime (e.g., datetime.datetime[tzinfo]).

The implementation:

  • Adds __class_getitem__ to datetime.datetime in both C and pure Python implementations
  • Follows the same pattern as other standard library types (Queue, etc.)
  • Includes comprehensive test coverage using tzinfo as the generic parameter
  • Does NOT add this functionality to other datetime module classes (date, time, timedelta, tzinfo, timezone)
  • Includes documentation with a versionchanged note for Python 3.15, using tzinfo in the example
Original prompt

Please tackle using the generic datetime in a runtime context, since the actual runtime datetime object doesn't support class_getitem().


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Dec 20, 2025
Copilot AI and others added 2 commits December 20, 2025 03:15
Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
… tests

Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
@m-aciek
Copy link
Copy Markdown
Owner

m-aciek commented Dec 20, 2025

@copilot Please add this only to datetime class, not to others in datetime module.

Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Dec 20, 2025

@copilot Please add this only to datetime class, not to others in datetime module.

Done. I've updated the implementation to add __class_getitem__ only to the datetime.datetime class. The changes have been applied to both the C implementation and the pure Python implementation. All other datetime module classes (date, time, timedelta, tzinfo, timezone) no longer have this method.

Commit: aa78e5f

Copilot AI changed the title [WIP] Fix datetime not supporting __class_getitem__ in runtime context Fix datetime.datetime not supporting __class_getitem__ in runtime context Dec 20, 2025
@m-aciek
Copy link
Copy Markdown
Owner

m-aciek commented Dec 20, 2025

@copilot Is there any change in the documentation needed?

Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Dec 20, 2025

@copilot Is there any change in the documentation needed?

Yes, I've added documentation for this feature. The datetime.rst file now includes a versionchanged directive for Python 3.15 that documents the new subscript operator support for creating generic aliases (e.g., datetime[int]). The note references PEP 585 and links to the Generic Alias Type section.

Commit: 3eeeb02

m-aciek pushed a commit that referenced this pull request Jan 23, 2026
…H-143076)

Add the unicodedata.iter_graphemes() function to iterate over grapheme
clusters according to rules defined in Unicode Standard Annex #29.

Add unicodedata.grapheme_cluster_break(), unicodedata.indic_conjunct_break()
and unicodedata.extended_pictographic() functions to get the properties
of the character which are related to the above algorithm.

Co-authored-by: Guillaume "Vermeille" Sanchez <guillaume.v.sanchez@gmail.com>
@m-aciek
Copy link
Copy Markdown
Owner

m-aciek commented Jan 23, 2026

@copilot Please update an example and test with generic over tzinfo instead of int

Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Jan 23, 2026

@copilot Please update an example and test with generic over tzinfo instead of int

Done. I've updated the documentation example to use datetime[tzinfo] instead of datetime[int], and updated the test to use tzinfo as the generic parameter in both single and multiple argument cases.

Commit: ffa9326

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants