Commit 6ff85d93 authored by Stefan Behnel's avatar Stefan Behnel

Avoid some unnecessary strlen() calls in exception text formatting, while...

Avoid some unnecessary strlen() calls in exception text formatting, while still keeping up the nice property of sharing const C message strings.
parent f4faa0ee
...@@ -5376,7 +5376,7 @@ class SimpleCallNode(CallNode): ...@@ -5376,7 +5376,7 @@ class SimpleCallNode(CallNode):
if formal_arg.not_none: if formal_arg.not_none:
if self.self: if self.self:
self.self = self.self.as_none_safe_node( self.self = self.self.as_none_safe_node(
"'NoneType' object has no attribute '%s'", "'NoneType' object has no attribute '%{0}s'".format('.30' if len(entry.name) <= 30 else ''),
error='PyExc_AttributeError', error='PyExc_AttributeError',
format_args=[entry.name]) format_args=[entry.name])
else: else:
...@@ -6758,7 +6758,7 @@ class AttributeNode(ExprNode): ...@@ -6758,7 +6758,7 @@ class AttributeNode(ExprNode):
format_args = () format_args = ()
if (self.obj.type.is_extension_type and self.needs_none_check and not if (self.obj.type.is_extension_type and self.needs_none_check and not
self.is_py_attr): self.is_py_attr):
msg = "'NoneType' object has no attribute '%s'" msg = "'NoneType' object has no attribute '%{0}s'".format('.30' if len(self.attribute) <= 30 else '')
format_args = (self.attribute,) format_args = (self.attribute,)
elif self.obj.type.is_memoryviewslice: elif self.obj.type.is_memoryviewslice:
if self.is_memslice_transpose: if self.is_memslice_transpose:
......
...@@ -892,7 +892,7 @@ class IterationTransform(Visitor.EnvTransform): ...@@ -892,7 +892,7 @@ class IterationTransform(Visitor.EnvTransform):
method_node = ExprNodes.StringNode( method_node = ExprNodes.StringNode(
dict_obj.pos, is_identifier=True, value=method) dict_obj.pos, is_identifier=True, value=method)
dict_obj = dict_obj.as_none_safe_node( dict_obj = dict_obj.as_none_safe_node(
"'NoneType' object has no attribute '%s'", "'NoneType' object has no attribute '%{0}s'".format('.30' if len(method) <= 30 else ''),
error = "PyExc_AttributeError", error = "PyExc_AttributeError",
format_args = [method]) format_args = [method])
else: else:
...@@ -2766,7 +2766,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin, ...@@ -2766,7 +2766,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
if is_list: if is_list:
type_name = 'List' type_name = 'List'
obj = obj.as_none_safe_node( obj = obj.as_none_safe_node(
"'NoneType' object has no attribute '%s'", "'NoneType' object has no attribute '%.30s'",
error="PyExc_AttributeError", error="PyExc_AttributeError",
format_args=['pop']) format_args=['pop'])
else: else:
...@@ -3456,7 +3456,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin, ...@@ -3456,7 +3456,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
format_args=['decode', string_type.name]) format_args=['decode', string_type.name])
else: else:
string_node = string_node.as_none_safe_node( string_node = string_node.as_none_safe_node(
"'NoneType' object has no attribute '%s'", "'NoneType' object has no attribute '%.30s'",
error="PyExc_AttributeError", error="PyExc_AttributeError",
format_args=['decode']) format_args=['decode'])
elif not string_type.is_string and not string_type.is_cpp_string: elif not string_type.is_string and not string_type.is_cpp_string:
...@@ -3653,7 +3653,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin, ...@@ -3653,7 +3653,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
format_args=[attr_name, function.obj.name]) format_args=[attr_name, function.obj.name])
else: else:
self_arg = self_arg.as_none_safe_node( self_arg = self_arg.as_none_safe_node(
"'NoneType' object has no attribute '%s'", "'NoneType' object has no attribute '%{0}s'".format('.30' if len(attr_name) <= 30 else ''),
error = "PyExc_AttributeError", error = "PyExc_AttributeError",
format_args = [attr_name]) format_args = [attr_name])
args[0] = self_arg args[0] = self_arg
......
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