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

invalid-format-index false positive #2752

Closed
ttsiodras opened this issue Feb 15, 2019 · 1 comment
Closed

invalid-format-index false positive #2752

ttsiodras opened this issue Feb 15, 2019 · 1 comment
Labels

Comments

@ttsiodras
Copy link

The issue is NOT fixed on the preview release.

Steps to reproduce

  1. Use this file
    #!/usr/bin/env python2
    '''
    A bug in pylint.
    '''
    import sys

    def main():
        '''Demonstrating the bug.'''
        options = []
        if len(sys.argv) > 1:
            options = [["Woof!"]]
        else:
            options = [["Barf!"]]
        print('Why is this bad? {options[0][0]}'.format(options=options))
        print("It's clearly a bug, since pylint thinks this is fine:", options[0][0])

    if __name__ == "__main__":
        main()
  1. Run pylint:
    $ pylint  bug.py  | grep -v '^$$' | sed -n '/^Report/q;p'

Current behavior

    $ pylint  bug.py  | grep -v '^$$' | sed -n '/^Report/q;p'
    ************* Module bug
    bug.py:14:10: W1307: Using invalid lookup key 0 in format specifier 'options[0]' (invalid-format-index)

Expected behavior

    $ pylint  bug.py  | grep -v '^$$' | sed -n '/^Report/q;p'

There is no bug here - and pylint reports nothing for the print command that follows, that uses exactly the same construct (options[0][0]).

pylint --version output

    $ pylint --version output
    pylint 2.3.0-dev1
    astroid 2.2.0-dev
    Python 3.5.3 (default, Sep 27 2018, 17:25:39)
    [GCC 6.3.0 20170516]

But also with the current version that pip3 installs:

    $ pip3 install pylint astroid
    ...
    $ pylint --version output
    pylint 2.2.2
    astroid 2.1.0
    Python 3.5.3 (default, Sep 27 2018, 17:25:39)
    [GCC 6.3.0 20170516]
    
    $ pylint  bug.py  | grep -v '^$$' | sed -n '/^Report/q;p'
    ************* Module bug
    bug.py:14:10: W1307: Using invalid lookup key 0 in format specifier 'options[0]' (invalid-format-index)
@PCManticore
Copy link
Contributor

Thanks, I can confirm the bug.

@PCManticore PCManticore changed the title False positive - correct construct works inside print, but not inside .format invalid-format-index false positive Feb 17, 2019
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