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
Prev Previous commit
Next Next commit
Add a simpler test.
  • Loading branch information
ericsnowcurrently committed Jun 12, 2024
commit a7d2f06a0236da5a94c4337e4594191d4e1c2b7f
47 changes: 30 additions & 17 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -6785,25 +6785,38 @@ def setUp(self):
self.skipTest('Not relevant in pure Python')

def test_gh_120161(self):
script = textwrap.dedent("""
import asyncio
import datetime
from typing import Type
with self.subTest('simple'):
script = textwrap.dedent("""
import datetime
from _ast import Tuple
f = lambda: None
Tuple.dims = property(f, f)

class tzutc(datetime.tzinfo):
pass
""")
script_helper.assert_python_ok('-c', script)

class tzutc(datetime.tzinfo):
pass
_EPOCHTZ = datetime.datetime(1970, 1, 1, tzinfo=tzutc())
with self.subTest('complex'):
script = textwrap.dedent("""
import asyncio
Copy link
Member

Choose a reason for hiding this comment

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

I would separate this test into its own method, it imports asyncio. Which means that it needs @requires_working_socket() decorator

Copy link
Member

Choose a reason for hiding this comment

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

Btw, why does it need asyncio? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Because of the original issue (the snippet is taken almost verbatim).

Copy link
Member Author

Choose a reason for hiding this comment

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

Importing asyncio on its own is not enough to be a problem. I was able to verify that it works fine on a WASI build (where @requires_working_socket() would skip). This is also verified by the WASI CI check passing. Unless there is another reason to do so, I'd rather not add that decorator.

import datetime
from typing import Type

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)
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):
Expand Down
0