@@ -358,30 +358,7 @@ def __ror__(self, other):
358358except ImportError :
359359 _tuplegetter = lambda index , doc : property (_itemgetter (index ), doc = doc )
360360
361- def namedtuple (typename , field_names , * , rename = False , defaults = None , module = None , _classcell = None ):
362- """Returns a new subclass of tuple with named fields.
363-
364- >>> Point = namedtuple('Point', ['x', 'y'])
365- >>> Point.__doc__ # docstring for the new class
366- 'Point(x, y)'
367- >>> p = Point(11, y=22) # instantiate with positional args or keywords
368- >>> p[0] + p[1] # indexable like a plain tuple
369- 33
370- >>> x, y = p # unpack like a regular tuple
371- >>> x, y
372- (11, 22)
373- >>> p.x + p.y # fields also accessible by name
374- 33
375- >>> d = p._asdict() # convert to a dictionary
376- >>> d['x']
377- 11
378- >>> Point(**d) # convert from a dictionary
379- Point(x=11, y=22)
380- >>> p._replace(x=100) # _replace() is like str.replace() but targets named fields
381- Point(x=100, y=22)
382-
383- """
384-
361+ def _namedtuple (typename , field_names , * , rename = False , defaults = None , module = None , classcell = None ):
385362 # Validate the field names. At the user's option, either generate an error
386363 # message or automatically replace the field name with a valid name.
387364 if isinstance (field_names , str ):
@@ -509,8 +486,8 @@ def __getnewargs__(self):
509486 '__match_args__' : field_names ,
510487 }
511488
512- if _classcell is not None :
513- class_namespace ["__classcell__" ] = _classcell
489+ if classcell is not None :
490+ class_namespace ["__classcell__" ] = classcell
514491
515492 for index , name in enumerate (field_names ):
516493 doc = _sys .intern (f'Alias for field number { index } ' )
@@ -536,6 +513,30 @@ def __getnewargs__(self):
536513
537514 return result
538515
516+ def namedtuple (typename , field_names , * , rename = False , defaults = None , module = None ):
517+ """Returns a new subclass of tuple with named fields.
518+
519+ >>> Point = namedtuple('Point', ['x', 'y'])
520+ >>> Point.__doc__ # docstring for the new class
521+ 'Point(x, y)'
522+ >>> p = Point(11, y=22) # instantiate with positional args or keywords
523+ >>> p[0] + p[1] # indexable like a plain tuple
524+ 33
525+ >>> x, y = p # unpack like a regular tuple
526+ >>> x, y
527+ (11, 22)
528+ >>> p.x + p.y # fields also accessible by name
529+ 33
530+ >>> d = p._asdict() # convert to a dictionary
531+ >>> d['x']
532+ 11
533+ >>> Point(**d) # convert from a dictionary
534+ Point(x=11, y=22)
535+ >>> p._replace(x=100) # _replace() is like str.replace() but targets named fields
536+ Point(x=100, y=22)
537+
538+ """
539+ return _namedtuple (typename , field_names , rename = rename , defaults = defaults , module = module )
539540
540541########################################################################
541542### Counter
0 commit comments