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

pylint trigger false-positive no-member error when using pathlib.Path parents function #5783

Closed
trym-b opened this issue Feb 9, 2022 · 4 comments
Labels
Duplicate 🐫 Duplicate of an already existing issue False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@trym-b
Copy link

trym-b commented Feb 9, 2022

Bug description

Pylint finds a false-positive when running the code below:

from pathlib import Path


def _main() -> None:
    current_path = Path().resolve()
    parent_path = current_path.parents[2].resolve()
    print(f"{current_path=}")
    print(f"{parent_path=}")


if __name__ == "__main__":
    _main()

When the code is run like this: python /path/to/script/test.py, this is the output:

$ python test.py
current_path=PosixPath('/home/user_name/testing/pylint-no-member')
parent_path=PosixPath('/home')

However, when I run pylint with the following options pylint test.py --disable missing-module-docstring then this is the output:

pylint test.py --disable missing-module-docstring
************* Module test
test.py:6:18: E1101: Instance of 'tuple' has no 'resolve' member (no-member)

------------------------------------------------------------------
Your code has been rated at 3.75/10 (previous run: 3.75/10, +0.00)

Configuration

No response

Command used

pylint test.py --disable missing-module-docstring

Pylint output

pylint test.py --disable missing-module-docstring
************* Module test
test.py:6:18: E1101: Instance of 'tuple' has no 'resolve' member (no-member)

------------------------------------------------------------------
Your code has been rated at 3.75/10 (previous run: 3.75/10, +0.00)

Expected behavior


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

Pylint version

pylint 2.12.2
astroid 2.9.3
Python 3.10.2 (main, Jan 15 2022, 18:02:07) [GCC 9.3.0]

OS / Environment

Ubuntu 20.04

Additional dependencies

No response

@trym-b trym-b added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Feb 9, 2022
@DanielNoord DanielNoord added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Feb 9, 2022
@stephanlachnit
Copy link

Interestingly this only happens with Python 3.10, not with Python 3.9.

@deepyaman
Copy link

deepyaman commented Mar 2, 2022

Same as #5832. You can resolve this particular error for now by doing:

parent_path = current_path.resolve().parents[2]

@jacobtylerwalls
Copy link
Member

Thanks for reporting. Will close as a duplicate of #5832 (more discussion happened there).

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2022
@jacobtylerwalls jacobtylerwalls added the Duplicate 🐫 Duplicate of an already existing issue label Jun 29, 2022
@galah92
Copy link

galah92 commented Aug 9, 2022

I'm getting the same issue with the following code:

cwd = Path(__file__).resolve().parents[1]
apps_paths = cwd.glob('apps/*')

On Python 10 as well. Is there an expected fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants