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 BTaskaya
Recipients BTaskaya, barry, brett.cannon, eric.smith, gousaiyang, gvanrossum, levkivskyi, lukasz.langa, methane, miss-islington, pablogsal, serhiy.storchaka, terry.reedy, vstinner
Date 2021-04-23.20:35:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1619210129.53.0.547573692203.issue38605@roundup.psfhosted.org>
In-reply-to
Content
> Hopefully Batuhan has a recollection of what I am thinking of, there was some significant delay while we figured out what to do about some of these.

The major one that I'd recall is that inspect.signature() just uses whatever is in __annotations__ instead of resolving those. Now that __future__.annotations is not the default one, we can add a new option named 'resolve_annotations' and call typing.get_type_hints when activated. Here is a quick demo;

from __future__ import annotations

import inspect

def foo(a: int, b: int) -> str:
    ...

def _get_annotations(func, **signature_opts):
    signature = inspect.signature(func, **signature_opts)
    return {
        param.name: param.annotation
        for param in signature.parameters.values()  
    }

print('bare: ', _get_annotations(foo))
print('annotations resolved: ', _get_annotations(foo, resolve_annotations=True))


bare: {'a': 'int', 'b': 'int'}
annotations resolved: {'a': <class 'int'>, 'b': <class 'int'>}

This would be a clear feature for both PEP 563 users + people who are still using string annotations mixed with normal ones. What do you think Guido?
History
Date User Action Args
2021-04-23 20:35:29BTaskayasetrecipients: + BTaskaya, gvanrossum, barry, brett.cannon, terry.reedy, vstinner, eric.smith, methane, lukasz.langa, serhiy.storchaka, levkivskyi, pablogsal, miss-islington, gousaiyang
2021-04-23 20:35:29BTaskayasetmessageid: <1619210129.53.0.547573692203.issue38605@roundup.psfhosted.org>
2021-04-23 20:35:29BTaskayalinkissue38605 messages
2021-04-23 20:35:29BTaskayacreate