[Python-Dev] PEP 326 (quick location possibility) (original) (raw)
Gerrit Holl gerrit at nl.linux.org
Tue Jan 27 06:15:38 EST 2004
- Previous message: [Python-Dev] PEP 326 (quick location possibility)
- Next message: [Python-Dev] Re: PEP 326 (quick location possibility)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Josiah Carlson wrote:
Current behavior of min and max: 1. without arguments raises a TypeError 2. with a single non-sequence argument raises a TypeError 3. with an empty sequence as an argument raises a ValueError 4. with one argument that is a non-empty sequence returns the min or max of the sequence 5. with more than one argument returns the min or max of *args
To be more precise: not sequence but iterable:
def f(): ... yield 1; yield 2; yield 3 ... max(f()) 3
If we assume that no one is calling min or max without arguments in order to raise a TypeError (which seems like a reasonable assumption),
I'm not sure. Suppose I collect a number of things in a collection and pass it to max with *: max(mycollection). If, by error, mycollection is empty, I want a TypeError, not a silent failure because it suddenly started returning an object. Of course, I shouldn't use the '' form then, but I think it's a realistic scenario.
then replacing the TypeError exception for behavior 1 with the following seems reasonable: min() -> Min max() -> Max
I don't think I like this solution. I do like the idea of min/max, and had a recent use case when writing an Interval type, but I builtin type with a good name. I think 'extreme' would be a good name, where 'extreme(True)' would return an object behaving like Highest and 'extreme(False)' would return an object behaving like Lowest.
yours, Gerrit.
-- 246. If a man hire an ox, and he break its leg or cut the ligament of its neck, he shall compensate the owner with ox for ox. -- 1780 BC, Hammurabi, Code of Law
PrePEP: Builtin path type http://people.nl.linux.org/~gerrit/creaties/path/pep-xxxx.html Asperger's Syndrome - a personal approach: http://people.nl.linux.org/~gerrit/english/
- Previous message: [Python-Dev] PEP 326 (quick location possibility)
- Next message: [Python-Dev] Re: PEP 326 (quick location possibility)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]