diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py index 83d10aa1bd3397..355145387e355b 100644 --- a/Lib/_pydatetime.py +++ b/Lib/_pydatetime.py @@ -2348,16 +2348,7 @@ def __new__(cls, offset, name=_Omitted): return cls._create(offset, name) def __init_subclass__(cls): - # When deprecation ends replace with: - # raise TypeError("type 'datetime.timezone' is not an acceptable base type") - import warnings - warnings.warn( - "Subclassing 'datetime.timezone' is deprecated and scheduled for removal " - "in Python 3.15.", - DeprecationWarning, - stacklevel=2, - ) - super().__init_subclass__() + raise TypeError("type 'datetime.timezone' is not an acceptable base type") @classmethod def _create(cls, offset, name=None): diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index d4c002dd93a238..736e33c9b8d361 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -301,21 +301,7 @@ def test_inheritance(self): self.assertIsInstance(timezone.utc, tzinfo) self.assertIsInstance(self.EST, tzinfo) - def test_cannot_subclass_deprecation_warning(self): - if '_Fast' in self.__class__.__name__: - self.skipTest('Only run for Pure Python implementation') - - msg = ( - "Subclassing 'datetime.timezone' is deprecated and scheduled for removal " - "in Python 3.15." - ) - with self.assertWarnsRegex(DeprecationWarning, msg): - class MyTimezone(timezone): pass - def test_cannot_subclass(self): - if '_Pure' in self.__class__.__name__: - self.skipTest('Only run for Fast C implementation') - msg = "type 'datetime.timezone' is not an acceptable base type" with self.assertRaisesRegex(TypeError, msg): class MyTimezone(timezone): pass diff --git a/Misc/NEWS.d/next/Library/2024-01-17-16-34-00.gh-issue-112451.5y9enV.rst b/Misc/NEWS.d/next/Library/2024-01-17-16-34-00.gh-issue-112451.5y9enV.rst deleted file mode 100644 index d1b20fd1c2fae6..00000000000000 --- a/Misc/NEWS.d/next/Library/2024-01-17-16-34-00.gh-issue-112451.5y9enV.rst +++ /dev/null @@ -1,2 +0,0 @@ -Deprecate subclassing pure-Python ``datetime.timezone``. -This is consistent with C-extension implementation. diff --git a/Misc/NEWS.d/next/Library/2024-01-24-20-11-46.gh-issue-112451.7YrG4p.rst b/Misc/NEWS.d/next/Library/2024-01-24-20-11-46.gh-issue-112451.7YrG4p.rst new file mode 100644 index 00000000000000..5717854badce9b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-01-24-20-11-46.gh-issue-112451.7YrG4p.rst @@ -0,0 +1,2 @@ +Prohibit subclassing pure-Python ``datetime.timezone``. This is consistent +with C-extension implementation. Patch by Mariusz Felisiak.