diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2017-09-10 17:23:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-10 17:23:36 (GMT) |
commit | 8b57d7363916869357848e666d03fa7614c47897 (patch) | |
tree | ce2c871ab523dbbf05bd80ee9dcfd1f2534d5798 /Doc/library | |
parent | 3cedf46cdbeefc019f4a672c1104f3d5e94712bd (diff) | |
download | cpython-8b57d7363916869357848e666d03fa7614c47897.zip cpython-8b57d7363916869357848e666d03fa7614c47897.tar.gz cpython-8b57d7363916869357848e666d03fa7614c47897.tar.bz2 |
bpo-28638: Optimize namedtuple() creation time by minimizing use of exec() (#3454)
* Working draft without _source
* Re-use itemgetter() instances
* Speed-up calls to __new__() with a pre-bound tuple.__new__()
* Add note regarding string interning
* Remove unnecessary create function wrappers
* Minor sync-ups with PR-2736. Mostly formatting and f-strings
* Bring-in qualname/__module fix-ups from PR-2736
* Formally remove the verbose flag and _source attribute
* Restore a test of potentially problematic field names
* Restore kwonly_args test but without the verbose option
* Adopt Inada's idea to reuse the docstrings for the itemgetters
* Neaten-up a bit
* Add news blurb
* Serhiy pointed-out the need for interning
* Jelle noticed as missing f on an f-string
* Add whatsnew entry for feature removal
* Accede to request for dict literals instead keyword arguments
* Leave the method.__module__ attribute pointing the actual location of the code
* Improve variable names and add a micro-optimization for an non-public helper function
* Simplify by in-lining reuse_itemgetter()
* Arrange steps in more logical order
* Save docstring in local cache instead of interning
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/collections.rst | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index d6d2056..cda8296 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -763,7 +763,7 @@ Named tuples assign meaning to each position in a tuple and allow for more reada self-documenting code. They can be used wherever regular tuples are used, and they add the ability to access fields by name instead of position index. -.. function:: namedtuple(typename, field_names, *, verbose=False, rename=False, module=None) +.. function:: namedtuple(typename, field_names, *, rename=False, module=None) Returns a new tuple subclass named *typename*. The new subclass is used to create tuple-like objects that have fields accessible by attribute lookup as @@ -786,10 +786,6 @@ they add the ability to access fields by name instead of position index. converted to ``['abc', '_1', 'ghi', '_3']``, eliminating the keyword ``def`` and the duplicate fieldname ``abc``. - If *verbose* is true, the class definition is printed after it is - built. This option is outdated; instead, it is simpler to print the - :attr:`_source` attribute. - If *module* is defined, the ``__module__`` attribute of the named tuple is set to that value. @@ -806,6 +802,9 @@ they add the ability to access fields by name instead of position index. .. versionchanged:: 3.6 Added the *module* parameter. + .. versionchanged:: 3.7 + Remove the *verbose* parameter and the :attr:`_source` attribute. + .. doctest:: :options: +NORMALIZE_WHITESPACE @@ -878,15 +877,6 @@ field names, the method and attribute names start with an underscore. >>> for partnum, record in inventory.items(): ... inventory[partnum] = record._replace(price=newprices[partnum], timestamp=time.now()) -.. attribute:: somenamedtuple._source - - A string with the pure Python source code used to create the named - tuple class. The source makes the named tuple self-documenting. - It can be printed, executed using :func:`exec`, or saved to a file - and imported. - - .. versionadded:: 3.3 - .. attribute:: somenamedtuple._fields Tuple of strings listing the field names. Useful for introspection |