Skip to content

Syntax error when docstring proceeds comment with type annotation #36

@JakubTesarek

Description

@JakubTesarek

When a function in source file contains both type annotation comment and docstring, but in wrong order, com2ann fails with SyntaxError.

Expected behaviour:

  • When the type comment is placed after docstring, it should be considered to be a basic inline comment and skipped.
  • Com2ann should skip the function and process the rest of the file.
  • The comment should be left in place so users can fix it themselves
  • Ideally there should an warning in the output informing user there was a function that was skipped due to misplaced type comment.

How to reproduce:
Create file test.py:

class Klass:
    def function(self, parameter):
        """Comment"""
        # type: (str) -> str
        return parameter

Call com2ann: com2ann test.py

Output:

File: test.py
SyntaxError in test.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions