[issue25981] Intern namedtuple field names

2016-04-26 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- resolution: -> duplicate stage: patch review -> resolved status: open -> closed ___ Python tracker ___ _

[issue25981] Intern namedtuple field names

2016-04-26 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I already opened separate issue26148. Since I sure this is the correct way, I'm closing this issue. I'll reopen it in case of issue26148 will be rejected. -- superseder: -> String literals are not interned if in a tuple _

[issue25981] Intern namedtuple field names

2016-04-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I think it would be better to change the compiler to always > intern short string literals. And patching namedtuple will > be not needed. Can we close this entry? If you do patch the compiler, a separate tracker item can be opened. -- assignee

[issue25981] Intern namedtuple field names

2016-01-01 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Interesting, short string literals usually are interned, but they are not interned in tuple literal. >>> namespace = {} >>> exec('a = ["abc123"]\ndef abc123(): pass', namespace) >>> namespace['abc123'].__name__ is namespace['a'][0] True >>> exec('a = ("abc123

[issue25981] Intern namedtuple field names

2016-01-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: The benefits are tiny, but if the one line patch looks good, we might as well intern the _fields and save a few bytes. -- ___ Python tracker ___

[issue25981] Intern namedtuple field names

2015-12-31 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Now, after you pointed out that the keys in the dictionary already interned, I'm not sure anymore that it is needed to intern the _fields items. I'm wondering, why short identifier-like string literals in compiled _fields are not interned? -- _

[issue25981] Intern namedtuple field names

2015-12-30 Thread Raymond Hettinger
Changes by Raymond Hettinger : Added file: http://bugs.python.org/file41458/show_all_fieldnames_interned2.py ___ Python tracker ___ ___ Python

[issue25981] Intern namedtuple field names

2015-12-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: I don't see how the proposed patch would affect the result. ISTM that the interning would have to happen after the template substitution and exec. See the attached alternate patch. That said, I'm not too concerned with the contents of _fields not being i

[issue25981] Intern namedtuple field names

2015-12-30 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Indeed, keys of __dict__ are interned. But elements of _fields are not. >>> A = namedtuple('A', 'abc123 def456') >>> sorted(A.__dict__)[-1] == A._fields[-1] True >>> sorted(A.__dict__)[-1] is A._fields[-1] False -- ___

[issue25981] Intern namedtuple field names

2015-12-30 Thread Raymond Hettinger
Changes by Raymond Hettinger : Added file: http://bugs.python.org/file41455/show_all_fieldnames_interned.py ___ Python tracker ___ ___ Python-

[issue25981] Intern namedtuple field names

2015-12-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: Doesn't interning happen already as a byproduct of the exec? -- ___ Python tracker ___ ___ Python

[issue25981] Intern namedtuple field names

2015-12-30 Thread Serhiy Storchaka
New submission from Serhiy Storchaka: If intern field names in namedtuple, this will speed up the access to them, because names could be compared just by identity in dict lookup. This can also make pickles containing namedtuples more compact. -- assignee: rhettinger components: Library