Аннотация Python 3.6+ аргумента, который может иметь строку или любой классPython

Программы на Python
Anonymous
Аннотация Python 3.6+ аргумента, который может иметь строку или любой класс

Сообщение Anonymous »

from typing import Union, Callable, Any

def map_type(t) -> str:
if isinstance(t, str):
_type = t
else:
_type = t.__name__
return {
'float': 'float',
'int': 'integer',
'number': 'float',
'bool': 'boolean',
'date': 'date',
'datetime': 'datetime',
'list': 'list',
'str': 'string'
}.get(_type)

Что тогда писать для аннотации t?
def map_type(t: Union[str, Any])->str: pass


Подробнее здесь: https://stackoverflow.com/questions/543 ... -any-class

Вернуться в «Python»