You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Specialisation fail LOAD_ATTR_INSTANCE_VALUE specialised when no instance variable #158934
deftest_load_attr_class_default_not_set_on_instance(self):
classC:
timeout=30defset_timeout(self, value):
self.timeout=value# puts "timeout" in C's shared keysc=C() # never sets timeout, so c.timeout is the class default@reset_codedefget_timeout(n):
for_inrange(n):
value=c.timeoutreturnvalueself.assertEqual(get_timeout(_testinternalcapi.SPECIALIZATION_THRESHOLD), 30)
# Must load the class attribute, not specialize as an instance# attribute load that misses on every execution.self.assert_specialized(get_timeout, "LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES")
self.assert_no_opcode(get_timeout, "LOAD_ATTR_INSTANCE_VALUE")
# Setting the attribute on the instance must be seen.c.set_timeout(5)
self.assertEqual(get_timeout(1), 5)
This is due to instance_has_key returning True even if setting an instance field is not actually set. Json dumps shows this issue with many instance level attributes not set by default relying on class level defaults
For json.dumps this can add about a 5% tax due to missed optimisations although it depends on the payload size. threading.Condition is another example from the stdlib.
Activity