From 4ccec95d2c23ddab9005a906312fa3608583942c Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 6 Aug 2023 03:41:53 -0400 Subject: [PATCH] Use the python source for the datetime module in Python 3.12+ (#2275) --- astroid/brain/brain_datetime.py | 19 +++---------------- tests/brain/test_dateutil.py | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/astroid/brain/brain_datetime.py b/astroid/brain/brain_datetime.py index e52c05b854..550d18dde7 100644 --- a/astroid/brain/brain_datetime.py +++ b/astroid/brain/brain_datetime.py @@ -2,8 +2,6 @@ # 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 @@ -11,20 +9,9 @@ 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: diff --git a/tests/brain/test_dateutil.py b/tests/brain/test_dateutil.py index a31128f34c..68cf640f8a 100644 --- a/tests/brain/test_dateutil.py +++ b/tests/brain/test_dateutil.py @@ -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"})