-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C-extension datetime.timezone
is not acceptable as a base class; pure-Python version is
#112451
Comments
Just to clarify: It is acceptable as a base class in Pure Python, but not in the C extension. |
datetime.timezone
is not acceptable as a base class
Working on patch |
datetime.timezone
is not acceptable as a base classdatetime.timezone
is not acceptable as a base class; pure-Python version is
I think @abalkin would know better, but I think the no-subclassing behavior was deliberate. If that is the case we should probably fix it by preventing inheritance in the pure Python module. |
I'm fine with making them consistent in any way. Just let me know and I'll update my patch. |
…upported(). This test relied on the behavior of subclassing `datetime.timezone` which is not permitted by the C-extension version of CPython's `datetime` module. This restriction isn't enforced by the pure Python version, nor by PyPy. See python/cpython#112451 It's not critical, and doesn't test any Django behavior, so just remove it.
As far as I'm aware, there are reasonable use cases for class AvailableTimezone(datetime.timezone, enum.Enum):
... |
This comment was marked as outdated.
This comment was marked as outdated.
One of advantage of non-inheritable C-extension classes is that you can replace Fortunately, both But when make a class inheritable, you should check a lot of other details. Test with overridden |
Here is Alexander's original justification for not allowing timezone to be subclassed: #49344 (comment) I tend to agree with his reasoning, but I don't entirely understand the enum example given by @felixxm here. Why exactly does it need to be a subclass? |
Thanks for chiming in @pganssle and @serhiy-storchaka. I see this is not as straight-forward as I thought. If any change is to be done, it would have to be to follow up Paul's suggestion to disallow subclassing of the Python class. We can also just leave it as it is; there are plenty of cases where the C implementation of a module differs from the Python implementation. |
True, it's not probably not as useful as
Granted, but these small differences make things trickier when you try to support |
This is consistent with C-extension datetime.timezone.
I've submitted a new PR to make both implementation consistent, #114190. |
This is consistent with C-extension datetime.timezone.
This is consistent with C-extension datetime.timezone.
This is consistent with C-extension datetime.timezone.
This is consistent with C-extension datetime.timezone.
This is consistent with C-extension datetime.timezone.
…14190) This is consistent with C-extension datetime.timezone.
…14190) This is consistent with C-extension datetime.timezone.
Bug report
Bug description:
Datetime has two modes. There is divergent behavior between the pure python and the c-extension
timezone
class, as found in djangoCPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: