[issue31085] Add option for namedtuple to name its result type automatically

2017-08-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Also it's far from clear that the pre-renaming field names are > what is wanted in the auto-generated typename. I concur. > Anyway I think I'm probably out at this point. Okay, marking this as closed. Thank you for the suggestion. Sorry this didn't

[issue31085] Add option for namedtuple to name its result type automatically

2017-08-02 Thread Isaac Morland
Isaac Morland added the comment: Not if one of the attributes is something that cannot be part of a typename: >>> fields = ['def', '-'] >>> namedtuple ('test', fields, rename=True).__doc__ 'test(_0, _1)' >>> namedtuple ('__'.join (fields), fields, rename=True).__doc__ Traceback (most recent

[issue31085] Add option for namedtuple to name its result type automatically

2017-08-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Your code will not work if rename=True is needed. It works just fine: >>> NT = auto_namedtuple('name', 'name', 'def', rename=True) >>> print(NT.__doc__) name_name_def(name, _1, _2) -- ___ Python

[issue31085] Add option for namedtuple to name its result type automatically

2017-08-02 Thread Isaac Morland
Isaac Morland added the comment: OK, so it's pretty clear this is heading towards a rejection, but I can't help but respond to your points: On 2 August 2017 at 01:12, Raymond Hettinger wrote: * This would be a potentially confusing addition to the API. > I'm giving a

[issue31085] Add option for namedtuple to name its result type automatically

2017-08-02 Thread R. David Murray
R. David Murray added the comment: Yeah, different developers have different opinions. We discuss (I'd say argue, which is accurate, but has acquired negative connotations) until we reach a consensus. And if we don't reach a consensus we leave it alone ("status quo wins a stalemate").

[issue31085] Add option for namedtuple to name its result type automatically

2017-08-02 Thread Isaac Morland
Isaac Morland added the comment: On 1 August 2017 at 14:32, R. David Murray wrote: > > R. David Murray added the comment: > > I wrote a "parameterized tests" extension for unittest, and it has the > option of autogenerating the test name from the parameter names and >

[issue31085] Add option for namedtuple to name its result type automatically

2017-08-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: [R David Murray] > So I vote -0.5. Put me down for a full -1: * This would be a potentially confusing addition to the API. * It may also encourage bad practices that we don't want to see in real code. * We want to be able to search for the namedtuple

[issue31085] Add option for namedtuple to name its result type automatically

2017-08-01 Thread R. David Murray
R. David Murray added the comment: The specialized use case is wanting to autogenerate a name with no other information provided. You suggested csv as one example where this would be used, but even in that case I'd rather see something based on the filename than a mashup of field names. I

[issue31085] Add option for namedtuple to name its result type automatically

2017-08-01 Thread Isaac Morland
Isaac Morland added the comment: First, another note I would like to point out: this is much nicer to write within namedtuple than as a wrapper function because it is trivial to use the existing rename logic when needed, as seen in the diff I provided. I suppose I could write a wrapper which

[issue31085] Add option for namedtuple to name its result type automatically

2017-08-01 Thread R. David Murray
R. David Murray added the comment: I think the "vaguely" pretty much says it, and you are the at least the first person who has *requested* it :) This is one of those cost-versus-benefit calculations. It is a specialized use case, and in other specialized use cases the "automatically

[issue31085] Add option for namedtuple to name its result type automatically

2017-07-31 Thread INADA Naoki
INADA Naoki added the comment: When subclassing, current __repr__ uses `self.__class__.__name__`. So you get meaningful name already. When automatic generation, I recommend you to use some wrapper to cache same namedtuple, since creating namedtuple on the fly is costly job. I'm afraid

[issue31085] Add option for namedtuple to name its result type automatically

2017-07-31 Thread Isaac Morland
Isaac Morland added the comment: I want a meaningful name to appear in debugging output generated by repr() or str(), not just _ all over the place. I just don't want to specifically come up with the meaningful name myself. Right now I pass in the same generated name ('__'.join

[issue31085] Add option for namedtuple to name its result type automatically

2017-07-31 Thread Raymond Hettinger
Raymond Hettinger added the comment: I concur with Steven. -- assignee: -> rhettinger ___ Python tracker ___

[issue31085] Add option for namedtuple to name its result type automatically

2017-07-30 Thread Ethan Furman
Changes by Ethan Furman : -- nosy: +ethan.furman ___ Python tracker ___ ___

[issue31085] Add option for namedtuple to name its result type automatically

2017-07-30 Thread Steven D'Aprano
Steven D'Aprano added the comment: If you don't care about the name, just pass '_' for it. -- nosy: +steven.daprano ___ Python tracker ___

[issue31085] Add option for namedtuple to name its result type automatically

2017-07-30 Thread Ned Deily
Changes by Ned Deily : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list

[issue31085] Add option for namedtuple to name its result type automatically

2017-07-30 Thread Isaac Morland
Isaac Morland added the comment: I'm hoping to make a pull request but while I figure that out here is the diff: diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 8408255..62cf708 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -384,7

[issue31085] Add option for namedtuple to name its result type automatically

2017-07-30 Thread Isaac Morland
New submission from Isaac Morland: I would like to have the possibility of creating a namedtuple type without explicitly giving it a name. I see two major use cases for this: 1) Automatic creation of namedtuples for things like CSV files with headers (see #1818) or SQL results (see #13299).