pathlib.Path.parents brain doesn't handle when parents is assigned to a variable
Bug description
On Python 3.14 with pylint 4.0.1, process this Python file:
# pylint: disable=missing-module-docstring
from pathlib import Path
cwd = Path.cwd()
parents = cwd.parents
print(parents[0].name)
This produces:
t.py:6:6: E1101: Instance of 'tuple' has no 'name' member (no-member)
This does not happen with Python 3.13.
(Related issue in the past: pylint-dev/pylint#5832)
Configuration
Command used
pylint t.py
Pylint output
************* Module t
t.py:6:6: E1101: Instance of 'tuple' has no 'name' member (no-member)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
Expected behavior
Pylint passes without reporting errors.
Pylint version
pylint 4.0.1
astroid 4.0.1
Python 3.14.0 (main, Oct 8 2025, 21:26:41) [GCC 14.2.0]
OS / Environment
python:3.14-slim Docker container with pip install pylint
Additional dependencies
Thanks for the report. Due to a quirk on python 3.13 this happens to work, but I think the deeper problem here is that the inference tip ("brain") implemented in pylint-dev/astroid#1442 only understands .parents[0], but here you've assigned .parent to a variable.
Inlining it works:
print(cwd.parents[0].name)
Moving this to the astroid repo to improve the brain.
/cc @deepyaman
/cc @deepyaman
Thanks for the tag! I'm happy to take a look at this for fun when I find some time, but, realistically, I haven't looked at astroid in the 3 years since I implemented the initial PR, and somebody else could probably get it done faster, if they're interested.
No worries! Appreciate even any partial findings you find from poking at it :-)
@jacobtylerwalls I’d like to take this issue! I’ll work on improving the brain_pathlib.py logic so that Path.parents inference also works when the attribute is assigned to a variable (e.g. parents = cwd.parents).
I’ll add a regression test under astroid/tests/brain/test_pathlib.py to verify the fix.
Please assign me if that’s okay — I’ll open a PR soon.
Thanks for the interest!
Thanks for assigning. Will get back with a PR soon.