This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mauvilsa
Recipients mauvilsa
Date 2021-07-13.07:41:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1626162078.24.0.194319586599.issue44618@roundup.psfhosted.org>
In-reply-to
Content
Classes in the datetime module are implemented using __new__ with some named parameters. I want to be able to inspect their signature to know which are the names of the parameters it accepts like it works for most classes. However, this does not work for classes in the datetime module. I already mentioned this in https://bugs.python.org/issue40897 but now I am thinking this should be a separate issue so I am creating this one.

An example is the class timedelta. It has as parameters days, seconds, microseconds, milliseconds, minutes, hours and weeks. If I run the following script trying different python versions

for py in 36 37 38 39; do
  source py${py}/bin/activate
  echo "=== $(python3 --version) ==="
  python3 -c "
from datetime import timedelta
import inspect
print(inspect.signature(timedelta.__new__))
print(inspect.signature(timedelta.__init__))
inspect.signature(timedelta)
"
  deactivate
done

What I get is

=== Python 3.6.9 ===
(*args, **kwargs)
(self, /, *args, **kwargs)
Traceback (most recent call last):
...
ValueError: no signature found for builtin type <class 'datetime.timedelta'>
=== Python 3.7.11 ===
(*args, **kwargs)
(self, /, *args, **kwargs)
Traceback (most recent call last):
...
ValueError: no signature found for builtin type <class 'datetime.timedelta'>
=== Python 3.8.11 ===
(*args, **kwargs)
(self, /, *args, **kwargs)
Traceback (most recent call last):
...
ValueError: no signature found for builtin type <class 'datetime.timedelta'>
=== Python 3.9.6 ===
(*args, **kwargs)
(self, /, *args, **kwargs)
Traceback (most recent call last):
...
ValueError: no signature found for builtin type <class 'datetime.timedelta'>
History
Date User Action Args
2021-07-13 07:41:18mauvilsasetrecipients: + mauvilsa
2021-07-13 07:41:18mauvilsasetmessageid: <1626162078.24.0.194319586599.issue44618@roundup.psfhosted.org>
2021-07-13 07:41:18mauvilsalinkissue44618 messages
2021-07-13 07:41:18mauvilsacreate