#StackBounty: #python #python-3.x #types #python-3.7 #static-typing inspect.signature with PEP 563

Bounty: 100

The following code:

import inspect
from typing import NamedTuple

class Example(NamedTuple):
    a: str

if __name__== "__main__":
    signature: inspect.Signature = inspect.signature(Example)
    print(signature)

outputs:

(a: str)

However when enabling PEP 563 – Postponed Evaluation of Annotations:

from __future__ import annotations
import inspect
from typing import NamedTuple

class Example(NamedTuple):
    a: str

if __name__== "__main__":
    signature: inspect.Signature = inspect.signature(Example)
    print(signature)

The output is:

(a: 'str')

How can I get the exact same object of type inspect.Signature with PEP 563 like without it?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.