New submission from Mauricio Villegas <mauricio_vi...@yahoo.com>:
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'> ---------- messages: 397387 nosy: mauvilsa priority: normal severity: normal status: open title: inspect.signature does not work for datetime classes versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44618> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com