TexteaInc / funix

Building web apps without manually creating widgets
http://funix.io
MIT License
90 stars 10 forks source link

Cannot use TypedDict #19

Closed forrestbao closed 2 years ago

forrestbao commented 2 years ago

Maybe I did something wrong, but I ran into the error to convert this Python code using PyDataFront:

$ python3 -m pydatafront bio.py 
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/forrest/Textea/PyDataFront/backend/pydatafront/__main__.py", line 11, in <module>
    importlib.import_module(parsed_sys_args.main_class)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/forrest/Textea/funcpool/bio.py", line 25, in <module>
    class telomere_check_return(typing.TypedDict):
  File "/home/forrest/Textea/PyDataFront/backend/pydatafront/decorator/__init__.py", line 33, in decorator
    function_signature = inspect.signature(function)
  File "/usr/lib/python3.10/inspect.py", line 3247, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
  File "/usr/lib/python3.10/inspect.py", line 2995, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
  File "/usr/lib/python3.10/inspect.py", line 2476, in _signature_from_callable
    sig = _get_signature_of(call)
  File "/usr/lib/python3.10/inspect.py", line 2529, in _signature_from_callable
    raise ValueError(
ValueError: no signature found for builtin type <class 'dict'>

I don't know why. Running bio.py has no error:

$ python3 bio.py
{'is_telomere': [False, True, False, True, True]}

I am using the latest version of PyDataFront:

commit d49a934250f95d88550994778fe4e6ec9494ed11 (HEAD -> main, origin/main, origin/HEAD)
Author: Ruixuan Tu <turx2003@gmail.com>
Date:   Thu Jul 7 06:50:54 2022 -0500

    fix: use backend path for setuptools package search to avoid conflict
himself65 commented 2 years ago

The reason is we haven't merged the PR #16

forrestbao commented 2 years ago

I just have this error again. See the end quote block.

Did we roll back too much?

My head is

commit 2de5baecd980ae316c43509dd8d2c4ef0051fa03 (HEAD -> main, origin/main, origin/HEAD)
Author: Ruixuan Tu <turx2003@gmail.com>
Date:   Sat Jul 9 10:38:57 2022 -0500

    feat: backend expose wrapper/function error to response
    issue: https://github.com/TexteaInc/PyDataFront/issues/22

This is the error again:

$ python3 -m pydatafront main
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/forrest/Textea/PyDataFront/backend/pydatafront/__main__.py", line 11, in <module>
    importlib.import_module(parsed_sys_args.main_class)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/forrest/Textea/funcpool/main.py", line 2, in <module>
    import bio
  File "/home/forrest/Textea/funcpool/bio.py", line 26, in <module>
    class telomere_check_return(typing.TypedDict):
  File "/home/forrest/Textea/PyDataFront/backend/pydatafront/decorator/__init__.py", line 76, in decorator
    function_signature = inspect.signature(function)
  File "/usr/lib/python3.10/inspect.py", line 3247, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
  File "/usr/lib/python3.10/inspect.py", line 2995, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
  File "/usr/lib/python3.10/inspect.py", line 2476, in _signature_from_callable
    sig = _get_signature_of(call)
  File "/usr/lib/python3.10/inspect.py", line 2529, in _signature_from_callable
    raise ValueError(
ValueError: no signature found for builtin type <class 'dict'>
forrestbao commented 2 years ago

I think I know what the error above is due to. It seems that I must define the return TypedDict type of a function before writing its decorator.

forrestbao commented 2 years ago

No I still have this issue when trying to let PyDataFront convert functions in https://github.com/TexteaInc/funcpool/blob/newbio/bio.py

forrestbao commented 2 years ago

Fixed. I made a mistake by putting code between a decorator and a function definition.