# HG changeset patch # User Paul Boddie # Date 1486222095 -3600 # Node ID 2846b907e92b8150af7151e9b51d6d8278f3e620 # Parent 2ee50dc501ca2066aebc23a44324be4f5415b8c9 Tidied up built-in class location computation. diff -r 2ee50dc501ca -r 2846b907e92b common.py --- a/common.py Sat Feb 04 15:35:58 2017 +0100 +++ b/common.py Sat Feb 04 16:28:15 2017 +0100 @@ -1237,21 +1237,22 @@ return assigned # Type and module functions. +# NOTE: This makes assumptions about the __builtins__ structure. def get_builtin_module(name): "Return the module name containing the given type 'name'." - # NOTE: This makes assumptions about the __builtins__ structure. - if name == "string": - return "str" + modname = "str" elif name == "utf8string": - return "unicode" + modname = "unicode" elif name == "NoneType": - return "none" + modname = "none" else: - return name + modname = name + + return "__builtins__.%s" % modname def get_builtin_type(name): @@ -1264,6 +1265,14 @@ else: return name +def get_builtin_class(name): + + "Return the full name of the built-in class having the given 'name'." + + typename = get_builtin_type(name) + module = get_builtin_module(typename) + return "%s.%s" % (module, typename) + # Useful data. predefined_constants = "False", "None", "NotImplemented", "True" diff -r 2ee50dc501ca -r 2846b907e92b generator.py --- a/generator.py Sat Feb 04 15:35:58 2017 +0100 +++ b/generator.py Sat Feb 04 16:28:15 2017 +0100 @@ -19,7 +19,7 @@ this program. If not, see . """ -from common import CommonOutput, get_builtin_module, get_builtin_type +from common import CommonOutput from encoders import encode_function_pointer, \ encode_instantiator_pointer, \ encode_literal_constant, encode_literal_constant_member, \ diff -r 2ee50dc501ca -r 2846b907e92b inspector.py --- a/inspector.py Sat Feb 04 15:35:58 2017 +0100 +++ b/inspector.py Sat Feb 04 16:28:15 2017 +0100 @@ -21,8 +21,7 @@ """ from branching import BranchTracker -from common import CommonModule, get_argnames, get_builtin_type, init_item, \ - predefined_constants +from common import CommonModule, get_argnames, init_item, predefined_constants from modules import BasicModule, CacheWritingModule, InspectionNaming from errors import InspectError from referencing import Reference @@ -1408,8 +1407,7 @@ else: value, typename, encoding = self.get_constant_value(n.value, n.literals) - name = get_builtin_type(typename) - ref = self.get_builtin_class(name) + ref = self.get_builtin_class(typename) return self.get_constant_reference(ref, value, encoding) # Special names. diff -r 2ee50dc501ca -r 2846b907e92b modules.py --- a/modules.py Sat Feb 04 15:35:58 2017 +0100 +++ b/modules.py Sat Feb 04 16:28:15 2017 +0100 @@ -20,7 +20,8 @@ this program. If not, see . """ -from common import get_builtin_module, init_item, remove_items, CommonModule +from common import get_builtin_class, get_builtin_module, init_item, \ + remove_items, CommonModule from encoders import decode_modifier_term, decode_usage, encode_modifiers, encode_usage from referencing import decode_reference, Reference from results import ResolvedNameRef @@ -301,15 +302,13 @@ "Return a reference to the actual object providing 'name'." - # NOTE: This makes assumptions about the __builtins__ structure. - - modname = get_builtin_module(name) - module_name = "__builtins__.%s" % modname + objpath = get_builtin_class(name) + module_name = get_builtin_module(name) if self.name != module_name: self.queue_module(module_name, True) - return Reference("", "__builtins__.%s.%s" % (modname, name)) + return Reference("", objpath) def get_object(self, path, defer=True): diff -r 2ee50dc501ca -r 2846b907e92b translator.py --- a/translator.py Sat Feb 04 15:35:58 2017 +0100 +++ b/translator.py Sat Feb 04 16:28:15 2017 +0100 @@ -20,8 +20,7 @@ """ from common import CommonModule, CommonOutput, InstructionSequence, \ - first, get_builtin_module, get_builtin_type, init_item, \ - predefined_constants + first, get_builtin_class, init_item, predefined_constants from encoders import encode_access_instruction, \ encode_function_pointer, encode_literal_constant, \ encode_literal_instantiator, encode_instantiator_pointer, \ @@ -369,11 +368,7 @@ "Return a reference to the actual object providing 'name'." - # NOTE: This makes assumptions about the __builtins__ structure. - - modname = get_builtin_module(name) - typename = get_builtin_type(name) - return self.importer.get_object("__builtins__.%s.%s" % (modname, typename)) + return self.importer.get_object(get_builtin_class(name)) def is_method(self, path): @@ -473,8 +468,7 @@ return self.process_literal_sequence_node(n, name, ref, TrLiteralSequenceRef) else: value, typename, encoding = self.get_constant_value(n.value, n.literals) - name = get_builtin_type(typename) - ref = self.get_builtin_class(name) + ref = self.get_builtin_class(typename) value_type = ref.get_origin() path = self.get_namespace_path()