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

Example code doesn't work on python 3.9 #1

Closed
churnikov opened this issue Dec 28, 2020 · 1 comment
Closed

Example code doesn't work on python 3.9 #1

churnikov opened this issue Dec 28, 2020 · 1 comment

Comments

@churnikov
Copy link

churnikov commented Dec 28, 2020

I get the following error when I'm trying to run your example code with python 3.9

Code:

import typedparse
from typing import Optional


def main(file: str, number: Optional[int] = 6):
    """Display first lines of a file.

    Args:
        file: file to display
        number: number of lines to display
    """
    with open(file, "r") as f:
        for i in range(0, number):
            print(f.readline(), end="")


if __name__ == "__main__":
    typedparse.parse(main, generate_short_flags=True)

Error:

Traceback (most recent call last):
  File "/Users/nikita/Projects/personal/keynote-highlight/keynote_highlight/main.py", line 56, in <module>
    typedparse.parse(main, generate_short_flags=True)
  File "/Users/nikita/Library/Caches/pypoetry/virtualenvs/keynote-highlight-P7sqe0O--py3.9/lib/python3.9/site-packages/typedparse/__init__.py", line 27, in parse
    return ArgParserFactory(generate_short_flags=generate_short_flags).create(obj).parse()
  File "/Users/nikita/Library/Caches/pypoetry/virtualenvs/keynote-highlight-P7sqe0O--py3.9/lib/python3.9/site-packages/typedparse/argparse.py", line 132, in create
    return ArgParserLeaf(self._parser, obj, self._generate_short_flags)
  File "/Users/nikita/Library/Caches/pypoetry/virtualenvs/keynote-highlight-P7sqe0O--py3.9/lib/python3.9/site-packages/typedparse/argparse.py", line 90, in __init__
    kwargs.update(type=type_func or spec.get_class(tpe))
  File "/Users/nikita/Library/Caches/pypoetry/virtualenvs/keynote-highlight-P7sqe0O--py3.9/lib/python3.9/site-packages/typedparse/spec.py", line 180, in get_class
    m = getattr(m, comp)
AttributeError: module 'typing' has no attribute 'Optional[int]'

Process finished with exit code 1
@khud khud closed this as completed in cb0efc1 Dec 31, 2020
@khud
Copy link
Owner

khud commented Dec 31, 2020

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants