1.1 --- a/common.py Sat Dec 10 14:04:01 2016 +0100
1.2 +++ b/common.py Sat Dec 10 17:32:16 2016 +0100
1.3 @@ -915,6 +915,22 @@
1.4 assigned.append(attrname)
1.5 return assigned
1.6
1.7 +# Type and module functions.
1.8 +
1.9 +def get_builtin_module(name):
1.10 +
1.11 + "Return the module name containing the given type 'name'."
1.12 +
1.13 + # NOTE: This makes assumptions about the __builtins__ structure.
1.14 +
1.15 + return name == "string" and "str" or name == "NoneType" and "none" or name
1.16 +
1.17 +def get_builtin_type(name):
1.18 +
1.19 + "Return the type name provided by the given Python value 'name'."
1.20 +
1.21 + return name == "str" and "string" or name
1.22 +
1.23 # Useful data.
1.24
1.25 predefined_constants = "False", "None", "NotImplemented", "True"
2.1 --- a/generator.py Sat Dec 10 14:04:01 2016 +0100
2.2 +++ b/generator.py Sat Dec 10 17:32:16 2016 +0100
2.3 @@ -19,7 +19,7 @@
2.4 this program. If not, see <http://www.gnu.org/licenses/>.
2.5 """
2.6
2.7 -from common import CommonOutput
2.8 +from common import CommonOutput, get_builtin_module, get_builtin_type
2.9 from encoders import encode_bound_reference, encode_function_pointer, \
2.10 encode_instantiator_pointer, \
2.11 encode_literal_constant, encode_literal_constant_member, \
2.12 @@ -446,8 +446,8 @@
2.13
2.14 # NOTE: This makes assumptions about the __builtins__ structure.
2.15
2.16 - modname = value.__class__.__name__
2.17 - typename = modname == "str" and "string" or modname
2.18 + typename = get_builtin_type(value.__class__.__name__)
2.19 + modname = get_builtin_module(typename)
2.20 ref = Reference("<instance>", "__builtins__.%s.%s" % (modname, typename))
2.21
2.22 self.make_constant(f_decls, f_defs, ref, const_path, structure_name, value)
3.1 --- a/inspector.py Sat Dec 10 14:04:01 2016 +0100
3.2 +++ b/inspector.py Sat Dec 10 17:32:16 2016 +0100
3.3 @@ -21,7 +21,8 @@
3.4 """
3.5
3.6 from branching import BranchTracker
3.7 -from common import CommonModule, get_argnames, init_item, predefined_constants
3.8 +from common import CommonModule, get_argnames, get_builtin_type, init_item, \
3.9 + predefined_constants
3.10 from modules import BasicModule, CacheWritingModule, InspectionNaming
3.11 from errors import InspectError
3.12 from referencing import Reference
3.13 @@ -294,7 +295,7 @@
3.14
3.15 elif isinstance(n, compiler.ast.Const):
3.16 typename = n.value.__class__.__name__
3.17 - return self.get_literal_instance(n, typename == "str" and "string" or typename)
3.18 + return self.get_literal_instance(n, get_builtin_type(typename))
3.19
3.20 elif isinstance(n, compiler.ast.Dict):
3.21 return self.get_literal_instance(n, "dict")
3.22 @@ -1386,6 +1387,11 @@
3.23
3.24 "For node 'n', return a reference to an instance of 'name'."
3.25
3.26 + # Handle stray None constants (Sliceobj seems to produce them).
3.27 +
3.28 + if name == "NoneType":
3.29 + return self.process_name_node(compiler.ast.Name("None"))
3.30 +
3.31 # Get a reference to the built-in class.
3.32
3.33 ref = self.get_builtin_class(name)
4.1 --- a/modules.py Sat Dec 10 14:04:01 2016 +0100
4.2 +++ b/modules.py Sat Dec 10 17:32:16 2016 +0100
4.3 @@ -20,7 +20,7 @@
4.4 this program. If not, see <http://www.gnu.org/licenses/>.
4.5 """
4.6
4.7 -from common import init_item, remove_items, CommonModule
4.8 +from common import get_builtin_module, init_item, remove_items, CommonModule
4.9 from encoders import decode_modifier_term, decode_usage, encode_modifiers, encode_usage
4.10 from referencing import decode_reference, Reference
4.11 from results import ResolvedNameRef
4.12 @@ -299,11 +299,12 @@
4.13
4.14 # NOTE: This makes assumptions about the __builtins__ structure.
4.15
4.16 - modname = name == "string" and "str" or name
4.17 + modname = get_builtin_module(name)
4.18 + module_name = "__builtins__.%s" % modname
4.19
4.20 - module_name = "__builtins__.%s" % modname
4.21 if self.name != module_name:
4.22 self.queue_module(module_name, True)
4.23 +
4.24 return Reference("<class>", "__builtins__.%s.%s" % (modname, name))
4.25
4.26 def get_object(self, path, defer=True):
5.1 --- a/translator.py Sat Dec 10 14:04:01 2016 +0100
5.2 +++ b/translator.py Sat Dec 10 17:32:16 2016 +0100
5.3 @@ -321,7 +321,8 @@
5.4
5.5 # NOTE: This makes assumptions about the __builtins__ structure.
5.6
5.7 - return self.importer.get_object("__builtins__.%s.%s" % (name, name))
5.8 + modname = get_builtin_module(name)
5.9 + return self.importer.get_object("__builtins__.%s.%s" % (modname, name))
5.10
5.11 def is_method(self, path):
5.12
5.13 @@ -410,6 +411,11 @@
5.14 For node 'n', return a reference for the type of the given 'name'.
5.15 """
5.16
5.17 + # Handle stray None constants (Sliceobj seems to produce them).
5.18 +
5.19 + if name == "NoneType":
5.20 + return self.process_name_node(compiler.ast.Name("None"))
5.21 +
5.22 ref = self.get_builtin_class(name)
5.23
5.24 if name in ("dict", "list", "tuple"):