Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Make typer compatible with PEP 563 #43

Closed
lorddaedra opened this issue Jan 28, 2020 · 3 comments
Closed

[FEATURE] Make typer compatible with PEP 563 #43

lorddaedra opened this issue Jan 28, 2020 · 3 comments
Labels
feature New feature, enhancement or request

Comments

@lorddaedra
Copy link

Describe the bug

Traceback (most recent call last):
...
  File "/usr/local/lib/python3.8/site-packages/typer/main.py", line 586, in get_click_type
    raise RuntimeError(f"Type not yet supported: {annotation}")  # pragma no cover
RuntimeError: Type not yet supported: str

https://www.python.org/dev/peps/pep-0563/

To Reproduce

Add

from __future__ import annotations

...
@lorddaedra lorddaedra added the bug Something isn't working label Jan 28, 2020
@tiangolo tiangolo changed the title [BUG] Make typer compatible with PEP 563 [FEATURE] Make typer compatible with PEP 563 Apr 26, 2020
@tiangolo tiangolo added feature New feature, enhancement or request and removed bug Something isn't working labels Apr 26, 2020
@tiangolo
Copy link
Member

This is now supported as of version 0.2.1 🎉 🚀

@github-actions
Copy link

github-actions bot commented May 7, 2020

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

@github-actions github-actions bot closed this as completed May 7, 2020
@wizard-28
Copy link

This does not work anymore

Sample code:

from __future__ import annotations

import typer

app = typer.Typer()


def main():
    app()


@app.command()
def test(flag: list[str] = typer.Option(None, "--flag", "-f", help="A flag")):
    print(flag)


if __name__ == "__main__":
    main()

Error:

Traceback (most recent call last):
  File "test.py", line 18, in <module>
    main()
  File "test.py", line 9, in main
    app()
  File "/home/pop-os/.cache/pypoetry/virtualenvs/nala-j_krjJMS-py3.8/lib/python3.8/site-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
  File "/home/pop-os/.cache/pypoetry/virtualenvs/nala-j_krjJMS-py3.8/lib/python3.8/site-packages/typer/main.py", line 239, in get_command
    click_command = get_command_from_info(typer_instance.registered_commands[0])
  File "/home/pop-os/.cache/pypoetry/virtualenvs/nala-j_krjJMS-py3.8/lib/python3.8/site-packages/typer/main.py", line 425, in get_command_from_info
    ) = get_params_convertors_ctx_param_name_from_function(command_info.callback)
  File "/home/pop-os/.cache/pypoetry/virtualenvs/nala-j_krjJMS-py3.8/lib/python3.8/site-packages/typer/main.py", line 401, in get_params_convertors_ctx_param_name_from_function
    parameters = get_params_from_function(callback)
  File "/home/pop-os/.cache/pypoetry/virtualenvs/nala-j_krjJMS-py3.8/lib/python3.8/site-packages/typer/utils.py", line 11, in get_params_from_function
    type_hints = get_type_hints(func)
  File "/usr/lib/python3.8/typing.py", line 1264, in get_type_hints
    value = _eval_type(value, globalns, localns)
  File "/usr/lib/python3.8/typing.py", line 270, in _eval_type
    return t._evaluate(globalns, localns)
  File "/usr/lib/python3.8/typing.py", line 518, in _evaluate
    eval(self.__forward_code__, globalns, localns),
  File "<string>", line 1, in <module>
TypeError: 'type' object is not subscriptable

Related issue: #371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature, enhancement or request
Projects
None yet
Development

No branches or pull requests

3 participants