com2ann icon indicating copy to clipboard operation
com2ann copied to clipboard

SyntaxError with function type comment and annotated argument

Open mrolle45 opened this issue 3 years ago • 1 comments
trafficstars

Bug Report:

Example program:

def f(x: bool
	) -> foo:
	# type: (int) -> str
	pass

Result of com2ann:

def f(x: bool: int
        ) -> str:
        pass

The x: bool: int is a SyntaxError. In this situation, there are various ways to handle it:

  • Reject the function type comment. Preferably, output an explanation for the rejection.
  • If the function comment and the parameter annotation are the same, leave the parameter as is. In any event, you will have to examine the syntax tree for the function def and find the parameter annotations. If the function comment uses an ellipsis, then this does not apply; only the return type annotation is added.

mrolle45 avatar Aug 15 '22 00:08 mrolle45

Yes, this is a bug. We need to simply reject the type comment.

ilevkivskyi avatar Aug 16 '22 10:08 ilevkivskyi