Friday, 23 November 2018

inspect.signature with PEP 563

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?



from inspect.signature with PEP 563

No comments:

Post a Comment