This is consistent with C-extension datetime.timezone.
"timedelta(hours=24).")
return cls._create(offset, name)
+ def __init_subclass__(cls):
+ raise TypeError("type 'datetime.timezone' is not an acceptable base type")
+
@classmethod
def _create(cls, offset, name=None):
self = tzinfo.__new__(cls)
self.assertIsInstance(timezone.utc, tzinfo)
self.assertIsInstance(self.EST, tzinfo)
+ def test_cannot_subclass(self):
+ with self.assertRaises(TypeError):
+ class MyTimezone(timezone): pass
+
def test_utcoffset(self):
dummy = self.DT
for h in [0, 1.5, 12]:
--- /dev/null
+Prohibit subclassing pure-Python :class:`datetime.timezone`. This is consistent
+with C-extension implementation. Patch by Mariusz Felisiak.