flake8-annotations
flake8-annotations copied to clipboard
Add ANN300-level Error for Mixed Ellipses and Type Comments
As touched on in #92, the current definition of and support for ellipses in partial type comments clashes with guidance provided in PEP 484:
Sometimes you want to specify the return type for a function or method without (yet) specifying the argument types. To support this explicitly, the argument list may be replaced with an ellipsis. Example:
def send_email(address, sender, cc, bcc, subject, body): # type: (...) -> bool """Send an email message. Return True if successful.""" <code>
This plugin currently supports mixing of ellipses and types within the same type comment as a means for partial hinting. For example, from the README:
def foo(arg1, arg2):
# type: (..., bool) -> bool
pass
Will show arg1
as missing a type hint.
While technically valid code, this type of notation is ambiguous and causes tools like mypy to error:
error: Ellipses cannot accompany other argument types in function type signature
This issue proposes the addition of an ANN300
-level error to lint for this mixing of ellipses, as well as dropping explicit support for these annotations within the framework. This is considered a breaking change and will therefore be included in a major release. The new error may be introduced in a point release for compatibility evaluation, but will remain off by default until a major release.
Instead of doing this, maybe use 3.0 to drop support for type comments entirely. How often are they used nowadays in a non-Py2 codebase?
Follow-up edit: There is also discussion on deprecating type comments from Python https://mail.python.org/archives/list/[email protected]/thread/66JDHQ2I3U3CPUIYA43W7SPEJLLPUETG/
edit: Type comment support is going to be removed in v3.0
ran into this on valid, commented-out code using PEP 526 type hints - providing here as an example:
# class A():
# type: str
pass
results in:
foo.py: "flake8-annotations[ANN]" failed during execution due to SyntaxError('invalid syntax', ('<unknown>', 2, 13, '# type: str\n', 2, 16))
Run flake8 with greater verbosity to see more details
0
Moving to #151, I don't think this is related to this issue.