cog
cog copied to clipboard
Handle from future import annotations
When using lazy evaluation of annotations
from __future__ import annotations
Annotations are strings and must be evaluated first. Currently this triggers a hard-to-decipher error:
File "/usr/local/lib/python3.8/site-packages/cog/server/http.py", line 34, in create_app
InputType = get_input_type(predictor)
File "/usr/local/lib/python3.8/site-packages/cog/predictor.py", line 126, in get_input_type
f"Unsupported input type {human_readable_type_name(InputType)} for parameter `{name}`. Supported input types are: {readable_types_list(ALLOWED_INPUT_TYPES)}."
File "/usr/local/lib/python3.8/site-packages/cog/predictor.py", line 210, in human_readable_type_name
module = t.__module__
AttributeError: 'str' object has no attribute '__module__'
According to PEP 563, the proper solution is probably to use typing.get_type_hints(obj, globalns=None, localns=None).