Skip to content

Commit 4ccec95

Browse files
Use the python source for the datetime module in Python 3.12+ (#2275)
1 parent 63cd8a1 commit 4ccec95

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

astroid/brain/brain_datetime.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,16 @@
22
# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
33
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
44

5-
import textwrap
6-
75
from astroid.brain.helpers import register_module_extender
86
from astroid.builder import AstroidBuilder
97
from astroid.const import PY312_PLUS
108
from astroid.manager import AstroidManager
119

1210

1311
def datetime_transform():
14-
"""The datetime module was C-accelerated in Python 3.12, so we
15-
lack a Python source."""
16-
return AstroidBuilder(AstroidManager()).string_build(
17-
textwrap.dedent(
18-
"""
19-
class date: ...
20-
class time: ...
21-
class datetime(date): ...
22-
class timedelta: ...
23-
class tzinfo: ...
24-
class timezone(tzinfo): ...
25-
"""
26-
)
27-
)
12+
"""The datetime module was C-accelerated in Python 3.12, so use the
13+
Python source."""
14+
return AstroidBuilder(AstroidManager()).string_build("from _pydatetime import *")
2815

2916

3017
if PY312_PLUS:

tests/brain/test_dateutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ def test_parser(self):
2626
"""
2727
)
2828
d_type = next(module["d"].infer())
29-
self.assertEqual(d_type.qname(), "datetime.datetime")
29+
self.assertIn(d_type.qname(), {"_pydatetime.datetime", "datetime.datetime"})

0 commit comments

Comments
 (0)