Skip to content

Commit

Permalink
Use the python source for the datetime module in Python 3.12+ (#2275)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored Aug 6, 2023
1 parent 63cd8a1 commit 4ccec95
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
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"})

0 comments on commit 4ccec95

Please sign in to comment.