Skip to content

Use the python source for the datetime module in Python 3.12+ #2275

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 2 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 3 additions & 16 deletions astroid/brain/brain_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,16 @@
# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt

import textwrap

from astroid.brain.helpers import register_module_extender
from astroid.builder import AstroidBuilder
from astroid.const import PY312_PLUS
from astroid.manager import AstroidManager


def datetime_transform():
"""The datetime module was C-accelerated in Python 3.12, so we
lack a Python source."""
return AstroidBuilder(AstroidManager()).string_build(
textwrap.dedent(
"""
class date: ...
class time: ...
class datetime(date): ...
class timedelta: ...
class tzinfo: ...
class timezone(tzinfo): ...
"""
)
)
"""The datetime module was C-accelerated in Python 3.12, so use the
Python source."""
return AstroidBuilder(AstroidManager()).string_build("from _pydatetime import *")


if PY312_PLUS:
Expand Down
2 changes: 1 addition & 1 deletion tests/brain/test_dateutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ def test_parser(self):
"""
)
d_type = next(module["d"].infer())
self.assertEqual(d_type.qname(), "datetime.datetime")
self.assertIn(d_type.qname(), {"_pydatetime.datetime", "datetime.datetime"})