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

Variable length tuple (Tuple[T, ...]) type hint as keyword argument gives false positive as "bad-whitespace" #1992

Closed
tuukkamustonen opened this issue Apr 4, 2018 · 2 comments
Labels

Comments

@tuukkamustonen
Copy link

tuukkamustonen commented Apr 4, 2018

Steps to reproduce

def foo(t: Tuple[str, ...] = None):
    pass

pylint test.py.

Current behavior

C:  1,28: No space allowed around keyword argument assignment
def foo(t: Tuple[str, ...] = None):
                           ^ (bad-whitespace)

Expected behavior

There shouldn't be violation.

http://mypy.readthedocs.io/en/latest/kinds_of_types.html#tuple-types recommends against variable length tuples:

Usually it’s a better idea to use Sequence[T] instead of Tuple[T, ...], as Sequence is also compatible with lists and other non-tuple sequences.

However, Tuple[T, ...] is supported, so pylint should support it, too.

pylint --version output

Latest from master:

No config file found, using default configuration
pylint 2.0.0
astroid 1.6.1
Python 3.5.5 (default, Mar 17 2018, 12:00:45) 
[GCC 5.4.0 20160609]
@PCManticore
Copy link
Contributor

Thanks for the issue! It's not a matter of pylint not supporting Tuple[T, ...], in fact we don't :) We don't support type annotations in the same sense that mypy does. The error you're seeing is most likely a bug in our formatting checks, which are more akin to pycodestyle & flake8 checks rather than mypy. Nevertheless, this is a bug!

@amyreese
Copy link

amyreese commented Apr 9, 2018

This looks like an issue when using any type annotation with an ellipsis, including Tuple and Callable:

C:150, 0: No space allowed around keyword argument assignment
        initializer: Callable[...] = None,
                                   ^ (bad-whitespace)
C:151, 0: No space allowed around keyword argument assignment
        initargs: Tuple[Any, ...] = None,
                                  ^ (bad-whitespace)

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

3 participants