F. Leone
F. Leone

Reputation: 595

How do I return type hinting defined types

If I have the following:

def alert(self, text: str, color: str) -> str:

Can I get somehow the specified type of my arguments?

I tried using func.__code__.co_varnames & inspect.getargspec(func) without good results.

Upvotes: 1

Views: 78

Answers (2)

bentheiii
bentheiii

Reputation: 451

blue_note's answer won't work with __future__.annotations, introduced in python 3.7, use typing.get_type_hints instead.

Upvotes: 1

blue note
blue note

Reputation: 29061

The alert.__annotations__ has a dict with the types.

The key return describes the return value. All other keys are the names of the arguments.

Upvotes: 1

Related Questions