cog icon indicating copy to clipboard operation
cog copied to clipboard

Handle from future import annotations

Open elazarg opened this issue 3 years ago • 0 comments

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).

elazarg avatar May 10 '22 22:05 elazarg