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

Don't report multiple-statements for def + ellipsis #3224

Closed
mthuurne opened this issue Oct 30, 2019 · 3 comments
Closed

Don't report multiple-statements for def + ellipsis #3224

mthuurne opened this issue Oct 30, 2019 · 3 comments
Labels

Comments

@mthuurne
Copy link
Contributor

Code using type annotations often has no need for a function body and puts ellipsis (...) there to indicate that.

For example when using @overload:
(this was taken straight from PEP 484)

from typing import overload

@overload
def concat2(x: str, y: str) -> str: ...
@overload
def concat2(x: bytes, y: bytes) -> bytes: ...

Or when defining a protocol:
(when using a Python version before 3.8, you'll have to install typing_extensions and import Protocol from there)

from typing import Any, Protocol

class ComparableProto(Protocol):
    def __eq__(self, other: Any) -> bool: ...
    def __ne__(self, other: Any) -> bool: ...
    def __lt__(self, other: Any) -> bool: ...
    def __le__(self, other: Any) -> bool: ...
    def __gt__(self, other: Any) -> bool: ...
    def __ge__(self, other: Any) -> bool: ...

However, when using this syntax, PyLint 2.4.3 will report More than one statement on a single line (multiple-statements).

While it is technically correct that the ellipsis is a statement, it is used to indicate the absence of meaningful statements. So in my opinion it would be better to have a special case for not reporting the situation in which there are two statements, the first of which is def and the second of which is Ellipsis.

@PCManticore
Copy link
Contributor

Yeah, I think we can exempt these situations.

@mthuurne
Copy link
Contributor Author

mthuurne commented Nov 8, 2019

Thanks!

@mthuurne
Copy link
Contributor Author

mthuurne commented Nov 16, 2019

On my PC, the fix works for Protocols, but for some reason not for functions/methods. [...]

Never mind; it wasn't working for Protocols either, I messed up my local testing. Also I didn't realize that the fix for this was committed on master and not on the 2.4 branch and therefore wouldn't be in the 2.4.4 release anyway.

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

No branches or pull requests

2 participants