-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Issues accessing PurePath.parents
by index in Python 3.10
#5832
Comments
Thank you for opening the issue. Some checks have voluntarily different output for different python version. For example typing with It's possible that some checkers still do not take it into account properly (the tuple error seems fishy here). |
Hi @Pierre-Sassoulas, thanks for your quick response. Do you have any docs on how to use the |
This is a global option, ( If you think we can make it clearer there's an issue to make the doc better: #5038, do not hesitate to add a comment there :) |
Thanks, the doc explanation makes sense 🙂 Unfortunately, it doesn't make a difference for my checks.. |
@MerelTheisenQB With regards to this example, the reason for different behavior in Python 3.10 is actually because With regards to the solution, the simple thing to do is change it to: starter_path = Path(__file__).resolve().parents[3] as even the Haven't looked into the second issue at all. |
Thank you for the investigation @deepyaman, this indeed look like something that require an astroid update. |
@Pierre-Sassoulas Any chance you can provide a bit of guidance as to what that update might look like? I've been keen to understand how Astroid works, and this looks like a simple case to start with. My guess is that it would mean adding a brain like: if PY310_PLUS:
def _path_transform():
return astroid.parse('''
class Path:
@property
def parents(self):
return (Path(), Path())
''')
register_module_extender(astroid.MANAGER, 'pathlib', _path_transform) This way, I assume pylint/whatever is using Astroid would infer a tuple of
Happy to make a PR if preferable, but thought I'd ask in case I'm way off on this implementation. |
Just to provide an update, I've gotten to the following # Copyright (c) 2022 Deepyaman Datta <deepyaman.datta@utexas.edu>
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
from astroid import inference_tip
from astroid.const import PY310_PLUS
from astroid.exceptions import UseInferenceDefault
from astroid.manager import AstroidManager
from astroid.nodes.node_classes import Attribute, Slice, Subscript
def _looks_like_parents_subscript(node):
return (
isinstance(node, Subscript)
and isinstance(node.value, Attribute)
and node.value.attrname == "parents"
)
def infer_parents_subscript(subscript_node, context=None):
if isinstance(subscript_node.slice, Slice):
raise UseInferenceDefault
yield from subscript_node.value.expr.infer(context=context)
if PY310_PLUS:
AstroidManager().register_transform(
Subscript, inference_tip(infer_parents_subscript), _looks_like_parents_subscript
)
|
Sorry for the late reply :) I'm not an expert in astroid to be honest but this looks very nice, thank you for opening an astroid PR ! |
PurePath.parents
by index in Python 3.10
I guess this issue will be solved with the 2.12 release of astroid then? |
Yes and after |
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? Using |
In https://github.com/PyCQA/pylint/blob/v2.14.5/setup.cfg#L50 EDIT: But with PR #7153 astroid |
You can follow the release of pylint 2.15 by checking the 2.15.0 milestone. We still have some blocker and most maintainers are vacationning right now :) it's possible to install the current main using pip with git+SSH |
Bug description
We're running
pylint
as part of our CircleCI builds, which we run on Python 3.7, 3.8, 3.9 and have now added 3.10.We're using
pylint
version2.12.2
, and the checks succeed on all versions < python 3.10, but on 3.10 we see the following errors:E1101: Instance of 'tuple' has no 'resolve' member (no-member)
for:
I0021: Useless suppression of 'abstract-class-instantiated' (useless-suppression)
for:
If the above failures are fixed for Python 3.10 the checks will then fail on all builds with version < Python 3.10.
Command used
Pylint output
This is the output for the 3.10 build:
Expected behavior
I would expect
pylint
to give the same output for the various Python versions.Pylint version
The versions used for the respective Python builds:
The text was updated successfully, but these errors were encountered: