[Python-Dev] PEP 443 - Single-dispatch generic functions (original) (raw)
Ethan Furman ethan at stoneleaf.us
Thu May 23 20:38:05 CEST 2013
- Previous message: [Python-Dev] PEP 443 - Single-dispatch generic functions
- Next message: [Python-Dev] PEP 443 - Single-dispatch generic functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 05/23/2013 11:13 AM, Éric Araujo wrote:
Thanks for writing this PEP. Blessing one implementation for the stdlib and one official backport will make programmers’ lives a bit easier :)
>>> @fun.register(int) ... def (arg, verbose=False): ... if verbose: ... print("Strength in numbers, eh?", end=" ") ... print(arg) ... Does this work if the implementation function is called like the first decorated function? (I don’t know the proper terminology) e.g. >>> @fun.register(int) ... def fun(arg, verbose=False): ... if verbose: ... print("Strength in numbers, eh?", end=" ") ... print(arg) The precedent is 2.6+ properties, where prop.setter mutates and returns the property object, which then overwrites the previous name in the class dictionary.
Actually, properties return new instances:
--> class Test(object): ... _temp = 'fleeting' ... @property ... def temp(self): ... return self._temp ... @temp.setter ... def new_temp(self, value): ... self._temp = value ...
--> id(Test.temp) 30245384
--> id(Test.new_temp) 30246352
--> Test.temp is Test.new_temp False
--
Ethan
- Previous message: [Python-Dev] PEP 443 - Single-dispatch generic functions
- Next message: [Python-Dev] PEP 443 - Single-dispatch generic functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]