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 The Compiler
Recipients The Compiler, eric.smith, gvanrossum, kj, levkivskyi
Date 2021-03-15.18:29:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1615832993.8.0.0417125720427.issue43463@roundup.psfhosted.org>
In-reply-to
Content
Ah, I wasn't aware of that, thanks for the pointer! So what inspect does internally is:

    def _get_type_hints(func, **kwargs):
        try:
            return typing.get_type_hints(func, **kwargs)
        except Exception:
            # First, try to use the get_type_hints to resolve
            # annotations. But for keeping the behavior intact
            # if there was a problem with that (like the namespace
            # can't resolve some annotation) continue to use
            # string annotations
            return func.__annotations__

Which means there's even some "prior art" there already falling back to a string when the annotation couldn't be resolved. Doing so in typing.get_type_hints on a per-argument basis would thus also make inspect more consistent:

Right now,

    print(repr(inspect.signature(fun).parameters['b'].annotation))

in my example returns a string, but when changing the annotation for `a`, the returned annotation for `b` is now magically a `typing.Union` object.

(I personally would indeed expect inspect to resolve those annotations, but yeah, let's keep that in issue43355.)
History
Date User Action Args
2021-03-15 18:29:53The Compilersetrecipients: + The Compiler, gvanrossum, eric.smith, levkivskyi, kj
2021-03-15 18:29:53The Compilersetmessageid: <1615832993.8.0.0417125720427.issue43463@roundup.psfhosted.org>
2021-03-15 18:29:53The Compilerlinkissue43463 messages
2021-03-15 18:29:53The Compilercreate