8000 gh-120161: Fix a Crash in the _datetime Module by ericsnowcurrently · Pull Request #120182 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-120161: Fix a Crash in the _datetime Module #120182

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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add a test.
  • Loading branch information
ericsnowcurrently committed Jun 6, 2024
commit 1cb0da255a33edc2d2150823db7a6a75e684e77d
31 changes: 30 additions & 1 deletion Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import re
import struct
import sys
import textwrap
import unittest
import warnings

Expand All @@ -22,7 +23,7 @@

from test import support
from test.support import is_resource_enabled, ALWAYS_EQ, LARGEST, SMALLEST
from test.support import warnings_helper, no_rerun
from test.support import script_helper, warnings_helper, no_rerun

import datetime as datetime_module
from datetime import MINYEAR, MAXYEAR
Expand Down Expand Up @@ -6777,6 +6778,34 @@ def test_datetime_from_timestamp(self):
self.assertEqual(dt_orig, dt_rt)


class ExtensionModuleTests(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpython_only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but currently there's mostly no need. If the extension module ("_datetime") doesn't exist then the "fast" version of the test is never created, and the pure-Python version of the test already always skips. (See Lib/test/test_datetime.py.) Also note that @cpython_only would mean the test wouldn't be run for Python implementations that do provide a _datetime accelerator module.

All that said, I don't see any harm with adding @cpython_only on the new test method. I would certainly only expect it to fail on CPython. Thanks for bringing this up.


def setUp(self):
if self.__class__.__name__.endswith('Pure'):
self.skipTest('Not relevant in pure Python')

def test_gh_120161(self):
script = textwrap.dedent("""
import asyncio
import datetime
from typing import Type

class tzutc(datetime.tzinfo):
pass
_EPOCHTZ = datetime.datetime(1970, 1, 1, tzinfo=tzutc())

class FakeDateMeta(type):
def __instancecheck__(self, obj):
return True
class FakeDate(datetime.date, metaclass=FakeDateMeta):
pass
def pickle_fake_date(datetime_) -> Type[FakeDate]:
# A pickle function for FakeDate
return FakeDate
""")
script_helper.assert_python_ok('-c', script)


def load_tests(loader, standard_tests, pattern):
standard_tests.addTest(ZoneInfoCompleteTest())
return standard_tests
Expand Down
0