-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
AttributeInferenceError: Could not find original name for items in Import
#1085
Comments
Import
Sorry for missing this issue. I think it has been fixed in astroid 2.6.5 (e432bd2), do you confirm @gergelypolonkai ? |
I will check tomorrow morning (Central Europe time); i remember having it with 2.6.4, but donʼt remember if i tried 2.6.5 at all yet. |
No, it seems we have also bumped into this using 2.6.5. Attached is the CI output with 2.6.5 |
@gergelypolonkai I'd like to investigate this but will probably need some help. You probably still can't give any reproducible code right? I would be helpful if you could tell me what the Additionally it would be helpful if we could determine what diff --git a/astroid/mixins.py b/astroid/mixins.py
index 097fd1ea4..e69d4fcef 100644
--- a/astroid/mixins.py
+++ b/astroid/mixins.py
@@ -119,6 +119,9 @@ class ImportFromMixin(FilterStmtsMixin):
_asname = name
if asname == _asname:
return name
+ print("SELF:", self)
+ print("ASNAME:", asname)
+ print("NAMES:", self.names)
raise AttributeInferenceError(
"Could not find original name for {attribute} in {target!r}",
target=self, You can use |
No, as it happens in our company-internal code base, so it would be complicated to give access; I’m continuously trying to reproduce it in one of my open source repos, but it hasn’t happened yet. On line 52 we import an internal module ( BUT at the end, the culprit seems to be
How we got there beats me, though, as even our |
Hmm this will be very hard to reproduce. I only have some slight hints which don't really form a coherent theory yet. Because of the print of
https://github.com/PyCQA/astroid/blob/9363c34934f94124f4867caf1bdf8f6755201ccd/astroid/mixins.py#L112-L126 If you're up for it, we could try another diff: diff --git a/astroid/mixins.py b/astroid/mixins.py
index 097fd1ea4..3d4679d37 100644
--- a/astroid/mixins.py
+++ b/astroid/mixins.py
@@ -91,6 +91,8 @@ class ImportFromMixin(FilterStmtsMixin):
def do_import_module(self, modname=None):
"""return the ast for a module whose name is <modname> imported by <self>"""
+ print("SELF:", self)
+ print("MODNAME:", modname)
# handle special case where we are on a package node importing a module
# using the same name as the package, which may end in an infinite loop
# on relative imports Just to double check what import statement is actually failing. Based on the stacktrace this is where we actually enter |
OK, this on is big; the output is 479kbytes. |
What's the |
(Note that since i reported the issue line numbers changed, hence the change from the original Also, since then i found the offending(?) |
Does gripping for: Again, the following diff and the last printed results might be interesting: diff --git a/astroid/builder.py b/astroid/builder.py
index 273c46e33..85827322c 100644
--- a/astroid/builder.py
+++ b/astroid/builder.py
@@ -167,6 +167,9 @@ class AstroidBuilder(raw_building.InspectBuilder):
module.future_imports.add(symbol)
self.add_from_names_to_locals(from_node)
# handle delayed assattr nodes
+ print("MODULE:", module)
+ print("ASSATTR:", module._delayed_assattr)
for delayed in module._delayed_assattr:
self.delayed_assattr(delayed)
|
and after this comes the backtrace, which is the end of the output. |
Based on this I'm making an (somewhat educated guess) is L88 defining an attribute that references something that gets imported on L5? |
L5 is
and L88 (and its relevant surrounding) is:
|
For context, |
Hmm, this looks like code that I have to go now but I'll see tonight if I can connect some dots and see what is happening here. Thanks for all the help so far. I might come back with another |
Don’t ask what made me, but i tried a little change on my code and changed that
And now the astroid error is gone. I checked if i install |
Also, i still can’t reproduce the problem:
Even if i add an |
One of the problems I'm running into now is that diff --git a/astroid/bases.py b/astroid/bases.py
index 4b5114e12..0bd1f71a7 100644
--- a/astroid/bases.py
+++ b/astroid/bases.py
@@ -139,6 +139,8 @@ class Proxy:
def _infer_stmts(stmts, context, frame=None):
"""Return an iterator on statements inferred by each statement in *stmts*."""
+ print("STMTS:", stmts)
+ print("CONTEXT:", context)
inferred = False
if context is not None:
name = context.lookupname I can't get it to crash yet but I think a better representation of the crash is: import models
def func():
for _, value in models.__dict__.items():
if isinstance(value, type):
value.class_attribute += 1
class MyModel:
class_attribute = 1 We need t assignment to |
I've made it crash 🎉 Reproducing code: import models
def func():
for _, value in models.__dict__.items():
if isinstance(value, type):
value.class_attribute += 1
import re
class MyModel:
class_attribute = 1 |
@gergelypolonkai You'll be happy to know that I think I found a fix and created a PR that seems to pass CI. This should be available in |
Oh, that sounds great! I'll revert my workaround in the company repo later today and check it with master, just in case ;) Thanks for fixing it! |
Steps to reproduce
Cannot reproduce outside of our closed-source repository yet; help appreciated on that.
Current behavior
Pylint fails with a backtrace.
Based on what i found so far the import statement in question is
import re
, a Python builtin. If i leave nothing but that line in that file, the error persists. If i run the same version of Pylint/astroid in a completely separate repo with only one file with only that single import line, Pylint works as expected.Expected behavior
Since earlier versions of Pylint and astroid work as expected on the very same code base,
python -c "from astroid import __pkginfo__; print(__pkginfo__.version)"
output2.6.2
Python versions i tested with are 3.6.10 and 3.9.5. Pylint version i use is 2.9.3.
Backtrace
The text was updated successfully, but these errors were encountered: