Commit 9912e336 authored by Stefan Behnel's avatar Stefan Behnel

Make sure we always have a correct "qualified_name" for all symtab Entry instances.

Closes GH-2811.
parent 43bdeb03
...@@ -825,6 +825,7 @@ class Scope(object): ...@@ -825,6 +825,7 @@ class Scope(object):
if overridable: if overridable:
# names of cpdef functions can be used as variables and can be assigned to # names of cpdef functions can be used as variables and can be assigned to
var_entry = Entry(name, cname, py_object_type) # FIXME: cname? var_entry = Entry(name, cname, py_object_type) # FIXME: cname?
var_entry.qualified_name = self.qualify_name(name)
var_entry.is_variable = 1 var_entry.is_variable = 1
var_entry.is_pyglobal = 1 var_entry.is_pyglobal = 1
var_entry.scope = entry.scope var_entry.scope = entry.scope
...@@ -1037,6 +1038,7 @@ class BuiltinScope(Scope): ...@@ -1037,6 +1038,7 @@ class BuiltinScope(Scope):
else: else:
python_equiv = EncodedString(python_equiv) python_equiv = EncodedString(python_equiv)
var_entry = Entry(python_equiv, python_equiv, py_object_type) var_entry = Entry(python_equiv, python_equiv, py_object_type)
var_entry.qualified_name = self.qualify_name(name)
var_entry.is_variable = 1 var_entry.is_variable = 1
var_entry.is_builtin = 1 var_entry.is_builtin = 1
var_entry.utility_code = utility_code var_entry.utility_code = utility_code
...@@ -1060,6 +1062,7 @@ class BuiltinScope(Scope): ...@@ -1060,6 +1062,7 @@ class BuiltinScope(Scope):
type = self.lookup('type').type, # make sure "type" is the first type declared... type = self.lookup('type').type, # make sure "type" is the first type declared...
pos = entry.pos, pos = entry.pos,
cname = entry.type.typeptr_cname) cname = entry.type.typeptr_cname)
var_entry.qualified_name = self.qualify_name(name)
var_entry.is_variable = 1 var_entry.is_variable = 1
var_entry.is_cglobal = 1 var_entry.is_cglobal = 1
var_entry.is_readonly = 1 var_entry.is_readonly = 1
...@@ -1241,14 +1244,13 @@ class ModuleScope(Scope): ...@@ -1241,14 +1244,13 @@ class ModuleScope(Scope):
entry.is_builtin = 1 entry.is_builtin = 1
entry.is_const = 1 # cached entry.is_const = 1 # cached
entry.name = name entry.name = name
entry.qualified_name = '__builtin__.' + name
entry.cname = Naming.builtin_prefix + name entry.cname = Naming.builtin_prefix + name
self.cached_builtins.append(entry) self.cached_builtins.append(entry)
self.undeclared_cached_builtins.append(entry) self.undeclared_cached_builtins.append(entry)
else: else:
entry.is_builtin = 1 entry.is_builtin = 1
entry.name = name entry.name = name
entry.qualified_name = '__builtin__.' + name entry.qualified_name = self.builtin_scope().qualify_name(name)
return entry return entry
def find_module(self, module_name, pos, relative_level=-1): def find_module(self, module_name, pos, relative_level=-1):
...@@ -1712,6 +1714,7 @@ class ModuleScope(Scope): ...@@ -1712,6 +1714,7 @@ class ModuleScope(Scope):
type = Builtin.type_type, type = Builtin.type_type,
pos = entry.pos, pos = entry.pos,
cname = entry.type.typeptr_cname) cname = entry.type.typeptr_cname)
var_entry.qualified_name = entry.qualified_name
var_entry.is_variable = 1 var_entry.is_variable = 1
var_entry.is_cglobal = 1 var_entry.is_cglobal = 1
var_entry.is_readonly = 1 var_entry.is_readonly = 1
...@@ -2314,6 +2317,7 @@ class CClassScope(ClassScope): ...@@ -2314,6 +2317,7 @@ class CClassScope(ClassScope):
entry = self.declare_cfunction( entry = self.declare_cfunction(
name, type, pos=None, cname=cname, visibility='extern', utility_code=utility_code) name, type, pos=None, cname=cname, visibility='extern', utility_code=utility_code)
var_entry = Entry(name, name, py_object_type) var_entry = Entry(name, name, py_object_type)
var_entry.qualified_name = name
var_entry.is_variable = 1 var_entry.is_variable = 1
var_entry.is_builtin = 1 var_entry.is_builtin = 1
var_entry.utility_code = utility_code var_entry.utility_code = utility_code
......
# cython: language_level=3, binding=True # cython: language_level=3, binding=True, annotation_typing=False
# mode: run # mode: run
# tag: generators, python3, exceptions # tag: generators, python3, exceptions, gh2230, gh2811
print(end='') # test that language_level 3 applies immediately at the module start, for the first token. print(end='') # test that language_level 3 applies immediately at the module start, for the first token.
...@@ -553,6 +553,18 @@ def annotation_syntax(a: "test new test", b : "other" = 2, *args: "ARGS", **kwar ...@@ -553,6 +553,18 @@ def annotation_syntax(a: "test new test", b : "other" = 2, *args: "ARGS", **kwar
return result return result
def builtin_as_annotation(text: str):
# See https://github.com/cython/cython/issues/2811
"""
>>> builtin_as_annotation("abc")
a
b
c
"""
for c in text:
print(c)
async def async_def_annotations(x: 'int') -> 'float': async def async_def_annotations(x: 'int') -> 'float':
""" """
>>> ret, arg = sorted(async_def_annotations.__annotations__.items()) >>> ret, arg = sorted(async_def_annotations.__annotations__.items())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment