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

AttributeError: 'Entry' object has no attribute 'qualified_name' #2811

Closed
Leoyzen opened this issue Jan 23, 2019 · 8 comments
Closed

AttributeError: 'Entry' object has no attribute 'qualified_name' #2811

Leoyzen opened this issue Jan 23, 2019 · 8 comments

Comments

@Leoyzen
Copy link

Leoyzen commented Jan 23, 2019

------------------------------------------------------------
        answer = 0
        previous_digit = 0
        current_build = 0

        for character in text:
       ^
------------------------------------------------------------

slu/normalizers/age_normalizer.py:185:8: Compiler crash in IterationTransform

ModuleNode.body = StatListNode(age_normalizer.py:1:0)
StatListNode.stats[6] = StatListNode(age_normalizer.py:164:0)
StatListNode.stats[0] = PyClassDefNode(age_normalizer.py:164:0,
    doc = '\n    xxxxxxxxxx\n    ',
    name = 'ChineseNumberParser')
PyClassDefNode.body = StatListNode(age_normalizer.py:165:4)
StatListNode.stats[2] = CompilerDirectivesNode(age_normalizer.py:176:4)
CompilerDirectivesNode.body = StatListNode(age_normalizer.py:176:4)
StatListNode.stats[0] = DefNode(age_normalizer.py:176:4,
    is_cyfunction = True,
    is_staticmethod = True,
    modifiers = [...]/0,
    name = 'parse',
    needs_closure = True,
    np_args_idx = [...]/0,
    num_required_args = 1,
    outer_attrs = [...]/2,
    py_wrapper_required = True,
    reqd_kw_flags_cname = '0',
    used = True)
DefNode.body = StatListNode(age_normalizer.py:177:8,
    is_terminator = True)
StatListNode.stats[5] = ForInStatNode(age_normalizer.py:185:8)

Compiler crash traceback from this point on:
  File "Cython/Compiler/Visitor.py", line 180, in Cython.Compiler.Visitor.TreeVisitor._visit
  File "lib/python3.6/site-packages/Cython/Compiler/Optimize.py", line 190, in visit_ForInStatNode
    return self._optimise_for_loop(node, node.iterator.sequence)
  File "lib/python3.6/site-packages/Cython/Compiler/Optimize.py", line 200, in _optimise_for_loop
    if annotation.entry and annotation.entry.qualified_name == 'typing.Dict':
AttributeError: 'Entry' object has no attribute 'qualified_name'
Traceback (most recent call last):
  File "setup.py", line 17, in <module>
    "annotation_typing": False
  File "lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1097, in cythonize
    cythonize_one(*args)
  File "python3.6/site-packages/Cython/Build/Dependencies.py", line 1220, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: slu/normalizers/age_normalizer.py

It seems that Class Entry dont have a attribute named "qualified_name" in Cython/Compiler/Symtab.py.
When add "qualified_name=None" in class defination, the error is gone.

@scoder
Copy link
Contributor

scoder commented Jan 23, 2019

Thanks for the report. That may or may not be the right fix. Could you provide a short code snippet that results in this error?

@hoefling
Copy link

@scoder this error happens if you translate python code with typings and annotation_typing turned off. An MCVE:

spam.py

# cython: language_level=3

def f(text: str):
    for c in text:
        print(c)

setup.py

from setuptools import setup
from Cython.Build import cythonize

setup(ext_modules=cythonize('spam.py', compiler_directives={'annotation_typing': False}))

Running build_ext yields:

Compiling spam.py because it changed.
[1/1] Cythonizing spam.py

Error compiling Cython file:
------------------------------------------------------------
...
# cython: language_level=3

def f(text: str):
    for c in text:
   ^
------------------------------------------------------------

spam.py:4:4: Compiler crash in IterationTransform

ModuleNode.body = StatListNode(spam.py:3:0)
StatListNode.stats[0] = DefNode(spam.py:3:0,
    is_cyfunction = True,
    modifiers = [...]/0,
    name = 'f',
    np_args_idx = [...]/0,
    num_required_args = 1,
    outer_attrs = [...]/2,
    py_wrapper_required = True,
    reqd_kw_flags_cname = '0',
    used = True)
DefNode.body = StatListNode(spam.py:4:4)
StatListNode.stats[0] = ForInStatNode(spam.py:4:4)

Compiler crash traceback from this point on:
  File "Cython/Compiler/Visitor.py", line 180, in Cython.Compiler.Visitor.TreeVisitor._visit
  File "/usr/lib64/python3.6/site-packages/Cython/Compiler/Optimize.py", line 190, in visit_ForInStatNode
    return self._optimise_for_loop(node, node.iterator.sequence)
  File "/usr/lib64/python3.6/site-packages/Cython/Compiler/Optimize.py", line 200, in _optimise_for_loop
    if annotation.entry and annotation.entry.qualified_name == 'typing.Dict':
AttributeError: 'Entry' object has no attribute 'qualified_name'
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    setup(ext_modules=cythonize('spam.py', compiler_directives={'annotation_typing': False}))
  File "/usr/lib64/python3.6/site-packages/Cython/Build/Dependencies.py", line 1097, in cythonize
    cythonize_one(*args)
  File "/usr/lib64/python3.6/site-packages/Cython/Build/Dependencies.py", line 1220, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: spam.py

Tested with Python 3.6.8, Cython 0.29.4.

@hoefling
Copy link

If you change annotation_typing to True (or simply remove compiler directives), the module is translated correctly.

@scoder
Copy link
Contributor

scoder commented Apr 14, 2019

Thanks for the report and digging up the further hints.

@scoder scoder reopened this Apr 14, 2019
@scoder
Copy link
Contributor

scoder commented Apr 14, 2019

Hmm, that wasn't enough, it seems. Looking into it.

@scoder scoder closed this as completed in 9912e33 Apr 14, 2019
@scoder scoder modified the milestones: 0.29.7, 3.0 Apr 14, 2019
@hoefling
Copy link

Awesome! Thank you for all the good work and looking forward to the 3.0 release!

@da-woods
Copy link
Contributor

da-woods commented Feb 8, 2021

@scoder you tagged this with 0.29.7 but it looks like it only went into 3.0

@scoder
Copy link
Contributor

scoder commented Feb 9, 2021

@da-woods I changed my mind after the fix (2019-04-14), but didn't leave a message here why. Probably because it turned out that a backport wouldn't be easy enough due to some infrastructure dependencies in the code.

da-woods pushed a commit to da-woods/cython that referenced this issue Jun 6, 2021
da-woods pushed a commit to da-woods/cython that referenced this issue Jun 6, 2021
da-woods pushed a commit to da-woods/cython that referenced this issue Jun 6, 2021
da-woods pushed a commit to da-woods/cython that referenced this issue Jun 6, 2021
scoder pushed a commit that referenced this issue Jun 9, 2021
Closes #4214
Closes #2811

* Set "entry.qualified_name" for builtin types.
* Make sure we always have a correct "qualified_name" for all symtab Entry instances.
@scoder scoder modified the milestones: 3.0, 0.29.24 Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants