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

SyntaxError #59

Closed
hschult opened this issue Aug 15, 2023 · 3 comments · Fixed by #60
Closed

SyntaxError #59

hschult opened this issue Aug 15, 2023 · 3 comments · Fixed by #60

Comments

@hschult
Copy link

hschult commented Aug 15, 2023

Hi,

since updating to version 0.1.5 I get a SyntaxError with the following function:

def test(a="a"):
    """
    Title

    Parameters
    ----------
    a : str, default a
    """
    pass
Traceback (most recent call last):
  File "/workspace/.conda/flake/bin/pydoclint", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/main.py", line 254, in main
    violationsInAllFiles: Dict[str, List[Violation]] = _checkPaths(
                                                       ^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/main.py", line 354, in _checkPaths
    violationsInThisFile: List[Violation] = _checkFile(
                                            ^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/main.py", line 398, in _checkFile
    visitor.visit(tree)
  File "/workspace/.conda/flake/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/ast.py", line 426, in generic_visit
    self.visit(item)
  File "/workspace/.conda/flake/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/visitor.py", line 126, in visit_FunctionDef
    argViolations = self.checkArguments(node, parent_, doc)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/visitor.py", line 370, in checkArguments
    if not docArgs.equals(
           ^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/utils/arg.py", line 213, in equals
    verdict = self == other
              ^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/utils/arg.py", line 135, in __eq__
    return self.infoList == other.infoList
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/utils/arg.py", line 36, in __eq__
    return self.name == o.name and self._eq(self.typeHint, o.typeHint)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/utils/arg.py", line 105, in _eq
    str1_: str = unparseAnnotation(ast.parse(stripQuotes(str1)))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 1
    str, default a
                 ^
SyntaxError: invalid syntax

When I tried to switch to the other numpy equivalents a : str, default=a worked and a : str, default: a resulted in a different error:

Traceback (most recent call last):
  File "/workspace/.conda/flake/bin/pydoclint", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/main.py", line 254, in main
    violationsInAllFiles: Dict[str, List[Violation]] = _checkPaths(
                                                       ^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/main.py", line 354, in _checkPaths
    violationsInThisFile: List[Violation] = _checkFile(
                                            ^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/main.py", line 398, in _checkFile
    visitor.visit(tree)
  File "/workspace/.conda/flake/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/ast.py", line 426, in generic_visit
    self.visit(item)
  File "/workspace/.conda/flake/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/visitor.py", line 126, in visit_FunctionDef
    argViolations = self.checkArguments(node, parent_, doc)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/visitor.py", line 370, in checkArguments
    if not docArgs.equals(
           ^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/utils/arg.py", line 213, in equals
    verdict = self == other
              ^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/utils/arg.py", line 135, in __eq__
    return self.infoList == other.infoList
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/utils/arg.py", line 36, in __eq__
    return self.name == o.name and self._eq(self.typeHint, o.typeHint)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/site-packages/pydoclint/utils/arg.py", line 105, in _eq
    str1_: str = unparseAnnotation(ast.parse(stripQuotes(str1)))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.conda/flake/lib/python3.11/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 1
    str, default: a
    ^^^
SyntaxError: only single target (not tuple) can be annotated

I am not sure what either of the errors mean so thank you for your help in advance.

@jsh9
Copy link
Owner

jsh9 commented Aug 15, 2023

Hi @hschult , thank you for submitting this issue!

I pushed a simple fix. The syntax error now goes away, and the expected violations are showing.

To see the expected violations, please take a look at the code diff of the PR: https://github.com/jsh9/pydoclint/pull/60/files

edge_case_02_syntax_error_in_type_hints.py contains the test cases that you provided, and test_main.py contains the expected violations.

@jsh9 jsh9 closed this as completed in #60 Aug 15, 2023
@jsh9
Copy link
Owner

jsh9 commented Aug 15, 2023

Fixed. Please see version 0.1.7.

@hschult
Copy link
Author

hschult commented Aug 15, 2023

Wow, you are fast. Thank you so much for fixing it! :)

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

Successfully merging a pull request may close this issue.

2 participants