Skip to content

Impossible to use get_type_hints in main file #49

Description

@ChristianSauer

get_type_hints is used by Pydantic, dacite etc. to create their model classes, so it'S kinda important.

Currentliy, this is broken in main.py:

Traceback (most recent call last):
  File "***\main.py", line 40, in ar_v4
    data = dacite.from_dict(RequestData2, message)
  File "***\venv\lib\site-packages\dacite\core.py", line 43, in from_dict
    data_class_hints = get_type_hints(data_class, globalns=config.forward_references)
  File "C:\dev\python3.8\lib\typing.py", line 1220, in get_type_hints
    base_globals = sys.modules[base.__module__].__dict__
KeyError: 'main'

reproduction:

install dacite
in main.py

import dacite
import dataclasses

@dataclasses.dataclass
class RequestData2:
    product_number: int

def hello_world(request):
    message = request.get_json()
    data = dacite.from_dict(RequestData2, message)
    return ""

post some data to it and observe the error.

Workaround:

create another file and place your data classes in them

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions