1.1 --- a/common.py Sat Feb 04 15:35:58 2017 +0100
1.2 +++ b/common.py Sat Feb 04 16:28:15 2017 +0100
1.3 @@ -1237,21 +1237,22 @@
1.4 return assigned
1.5
1.6 # Type and module functions.
1.7 +# NOTE: This makes assumptions about the __builtins__ structure.
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 if name == "string":
1.16 - return "str"
1.17 + modname = "str"
1.18 elif name == "utf8string":
1.19 - return "unicode"
1.20 + modname = "unicode"
1.21 elif name == "NoneType":
1.22 - return "none"
1.23 + modname = "none"
1.24 else:
1.25 - return name
1.26 + modname = name
1.27 +
1.28 + return "__builtins__.%s" % modname
1.29
1.30 def get_builtin_type(name):
1.31
1.32 @@ -1264,6 +1265,14 @@
1.33 else:
1.34 return name
1.35
1.36 +def get_builtin_class(name):
1.37 +
1.38 + "Return the full name of the built-in class having the given 'name'."
1.39 +
1.40 + typename = get_builtin_type(name)
1.41 + module = get_builtin_module(typename)
1.42 + return "%s.%s" % (module, typename)
1.43 +
1.44 # Useful data.
1.45
1.46 predefined_constants = "False", "None", "NotImplemented", "True"
2.1 --- a/generator.py Sat Feb 04 15:35:58 2017 +0100
2.2 +++ b/generator.py Sat Feb 04 16:28:15 2017 +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, get_builtin_module, get_builtin_type
2.8 +from common import CommonOutput
2.9 from encoders import encode_function_pointer, \
2.10 encode_instantiator_pointer, \
2.11 encode_literal_constant, encode_literal_constant_member, \
3.1 --- a/inspector.py Sat Feb 04 15:35:58 2017 +0100
3.2 +++ b/inspector.py Sat Feb 04 16:28:15 2017 +0100
3.3 @@ -21,8 +21,7 @@
3.4 """
3.5
3.6 from branching import BranchTracker
3.7 -from common import CommonModule, get_argnames, get_builtin_type, init_item, \
3.8 - predefined_constants
3.9 +from common import CommonModule, get_argnames, init_item, predefined_constants
3.10 from modules import BasicModule, CacheWritingModule, InspectionNaming
3.11 from errors import InspectError
3.12 from referencing import Reference
3.13 @@ -1408,8 +1407,7 @@
3.14
3.15 else:
3.16 value, typename, encoding = self.get_constant_value(n.value, n.literals)
3.17 - name = get_builtin_type(typename)
3.18 - ref = self.get_builtin_class(name)
3.19 + ref = self.get_builtin_class(typename)
3.20 return self.get_constant_reference(ref, value, encoding)
3.21
3.22 # Special names.
4.1 --- a/modules.py Sat Feb 04 15:35:58 2017 +0100
4.2 +++ b/modules.py Sat Feb 04 16:28:15 2017 +0100
4.3 @@ -20,7 +20,8 @@
4.4 this program. If not, see <http://www.gnu.org/licenses/>.
4.5 """
4.6
4.7 -from common import get_builtin_module, init_item, remove_items, CommonModule
4.8 +from common import get_builtin_class, get_builtin_module, init_item, \
4.9 + remove_items, CommonModule
4.10 from encoders import decode_modifier_term, decode_usage, encode_modifiers, encode_usage
4.11 from referencing import decode_reference, Reference
4.12 from results import ResolvedNameRef
4.13 @@ -301,15 +302,13 @@
4.14
4.15 "Return a reference to the actual object providing 'name'."
4.16
4.17 - # NOTE: This makes assumptions about the __builtins__ structure.
4.18 -
4.19 - modname = get_builtin_module(name)
4.20 - module_name = "__builtins__.%s" % modname
4.21 + objpath = get_builtin_class(name)
4.22 + module_name = get_builtin_module(name)
4.23
4.24 if self.name != module_name:
4.25 self.queue_module(module_name, True)
4.26
4.27 - return Reference("<class>", "__builtins__.%s.%s" % (modname, name))
4.28 + return Reference("<class>", objpath)
4.29
4.30 def get_object(self, path, defer=True):
4.31
5.1 --- a/translator.py Sat Feb 04 15:35:58 2017 +0100
5.2 +++ b/translator.py Sat Feb 04 16:28:15 2017 +0100
5.3 @@ -20,8 +20,7 @@
5.4 """
5.5
5.6 from common import CommonModule, CommonOutput, InstructionSequence, \
5.7 - first, get_builtin_module, get_builtin_type, init_item, \
5.8 - predefined_constants
5.9 + first, get_builtin_class, init_item, predefined_constants
5.10 from encoders import encode_access_instruction, \
5.11 encode_function_pointer, encode_literal_constant, \
5.12 encode_literal_instantiator, encode_instantiator_pointer, \
5.13 @@ -369,11 +368,7 @@
5.14
5.15 "Return a reference to the actual object providing 'name'."
5.16
5.17 - # NOTE: This makes assumptions about the __builtins__ structure.
5.18 -
5.19 - modname = get_builtin_module(name)
5.20 - typename = get_builtin_type(name)
5.21 - return self.importer.get_object("__builtins__.%s.%s" % (modname, typename))
5.22 + return self.importer.get_object(get_builtin_class(name))
5.23
5.24 def is_method(self, path):
5.25
5.26 @@ -473,8 +468,7 @@
5.27 return self.process_literal_sequence_node(n, name, ref, TrLiteralSequenceRef)
5.28 else:
5.29 value, typename, encoding = self.get_constant_value(n.value, n.literals)
5.30 - name = get_builtin_type(typename)
5.31 - ref = self.get_builtin_class(name)
5.32 + ref = self.get_builtin_class(typename)
5.33 value_type = ref.get_origin()
5.34
5.35 path = self.get_namespace_path()