Hacker News new | past | comments | ask | show | jobs | submit login

You are correct, and I apologize for not looking into this more deeply first.

For the specific case under discussion, ncoghlan added cache_info() on 30 Nov 2010 - https://github.com/python/cpython/commit/234515afe594e5f9ca1...

Previously, "Performance statistics stored in f.cache_hits and f.cache_misses." With the change "Significant statistics (maxsize, size, hits, misses) are available through the f.cache_info() named tuple."

There was no time when it was a tuple, much less in a tuple in a public release.

I'll look first at the namedtuples which have been present since at least 2.7.10.

The named tuples in "urllib/parse", "difflib", "inspect", "sched", and "doctest" were originally tuples. The decimal module's uses a DecimalTuple as a return value from to_tuple(), so I didn't check that history.

ssl uses a DefaultVerifyPaths added by tiran on 9 Jun 2013 - https://github.com/python/cpython/commit/6d7ad13a458afdf2cbd... . It did not replace a tuple. I assume _ASN1Object is the same way.

Now for the namedtuples in recent version control:

dis.py:_Instruction was added in https://github.com/python/cpython/commit/b39fd0c9b8dc6683924... . It did not replace a tuple.

aifc.py:_aifc_params replaces a tuple.

crypt.py:_Method replaced a class with a namedtuple in https://github.com/python/cpython/commit/daa5799cb8866785543... .

nntplib.py:GroupInfo and ArticleInfo added in https://github.com/python/cpython/commit/69ab95105f5105b8337... . It did not replace a tuple.

pkgutil.py:ModuleInfo replaces a tuple

platform.py:uname_result replaces a tuple

sndhdr.py:SndHeader replaces a tuple

sunau.py:_sunau_params replaces a tuple

tokenize.py:TokenInfo replaces a tuple

typing.py:nm_tpl ... is above my paygrade to understand. I believe it's required to be a namedtuple since that what it's trying to implement.

wave.py:_wave_params replaces a tuple.

Finally, urllib/robotparser.py appears to contain a bug in the following:

  req_rate = collections.namedtuple('req_rate',
                                    'requests seconds')
  entry.req_rate = req_rate
  entry.req_rate.requests = int(numbers[0])
  entry.req_rate.seconds = int(numbers[1])
As I read it, this should fail as the req_rate is immutable. This appears to be written by someone who thinks that it's a lightweight object. The commit is https://github.com/python/cpython/commit/960e848f0d32399824d... . It did not replace a tuple.

In conclusion, 8 of the current uses of namedtuple are not to emulate a tuple. 13 of the current uses replace a tuple.




BTW, what tool did you use for your commit/diff search?


Brute force. grep to find where the namedtuples are used in version control and in Python 2.7, 'git annotate' to find the last time the 'namedtuple' code was touched, then manually browse the github history view to search for when the code was added.

If a given function was in python2.7 then it was easier. I checked if the code used to be a tuple.


Ah well. As far as I know, there's only BigQuery for full search of GitHub commits. They have some free usage, but it can quickly add up to $$ if you're not careful to restrict the query space.


Now that I think about it, I believe I could have used a git bisect using grep as the run command.


Good research. If you found a bug, report it!


Thank you. I will not. I reported a bug once and did not find the process at all enjoyable. It felt like several of the people in the thread thought my use case was stupid, and were quite blunt about it, to the point where I questioned my own competency. This bug isn't important enough for me to deal with that environment again.


That's frustrating. I've faced similar questions about use case, but the tone was simply that I'm an outlier rather than incompetent. Other times, the response has been quite pleasant and appreciative. I suppose it depends on which module you're reporting and who gets notified.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: