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

The disable declaration directives does not take effect when f-string exists #2449

Labels
Milestone

Comments

@jubel-han
Copy link

jubel-han commented Aug 29, 2018

Steps to reproduce

  1. Install the pylint with version <2.0.0 in docker container python:3.6.4
$ docker run --rm -it python:3.6.4 bash
root@f725efd48164:/# pip3 install "pylint<2.0.0"
Collecting pylint<2.0.0
... ...
Successfully installed astroid-1.6.5 pylint-1.9.3
  1. Inspect the installed packages and its version
root@f725efd48164:/# pip3 freeze
astroid==1.6.5
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
pylint==1.9.3
six==1.11.0
typed-ast==1.1.0
wrapt==1.10.11
  1. Create the python testing script file
root@f725efd48164:/# cat > test.py << EOF
> # pylint: disable=missing-docstring,unused-argument,unused-import
>
> import os
> import abc
>
>
> def func_foo(arg_bar, arg_foo):
>     dict_foo = {}
>
>     print(f'{arg_bar}')                 # disable declaration worked when it exists
>     print(f'{arg_bar.attr_bar}')        # disable declaration not working when it exists
>     print(f'{dict_foo["key_foo"]}')     # disable declaration not working when it exists
>
>     _ = 'A strange dummy line needed to be here to reproduce the issue'
> EOF
  1. Run the pylint against the test file
root@f725efd48164:/# pylint test.py
No config file found, using default configuration

-------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 7.50/10, +2.50)

Everything is expected since that we disabled them.

  1. Install the pylint with version >=2.0.0 and inspect the installed versions
root@f725efd48164:/# pip3 install "pylint>=2.0.0"
Collecting pylint>=2.0.0
... ...
Successfully installed astroid-2.0.4 pylint-2.1.1
root@f725efd48164:/# pip3 freeze
astroid==2.0.4
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
pylint==2.1.1
six==1.11.0
typed-ast==1.1.0
wrapt==1.10.11
  1. Run the pylint against the test file again.
root@f725efd48164:/# pylint test.py
************* Module test
/test.py:1:0: C0111: Missing module docstring (missing-docstring)
/test.py:7:0: C0111: Missing function docstring (missing-docstring)
/test.py:7:22: W0613: Unused argument 'arg_foo' (unused-argument)
/test.py:4:0: W0611: Unused import abc (unused-import)

-------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 10.00/10, -5.00)

root@f725efd48164:/#

From the above, we can see the disable directives didn't take effect.

Current behavior

The disable declaration does not take effects if the object's attribute invoked in the f-string as well as an extra line exists at below of the f-string one.

e.g.:

f_string = f'{object.attr}'
extra_line = 'a extra line in there'

Expected behavior

The disable declaration take effects no matter the above condition exists or not.

pylint --version output

appears at the above reproduce steps.

@jubel-han jubel-han changed the title The disable declaration directives does not effect when f-string exists The disable declaration directives does not take effect when f-string exists Aug 29, 2018
@PCManticore
Copy link
Contributor

Hey, thanks for creating an issue! I can definitely reproduce this bug.

@PCManticore
Copy link
Contributor

This should be fixed with the latest astroid's master, please give it a go and let us know if it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment