Re: Earwax

@103 looking at your examples of how decorators work, I dont think it is entirely true. reffering to your example:
@decorator
def f():
    pass
is the same as:
def f():
    pass
decorator(f)

In your example, the two cases are the same if and only if the decorator doesn't transform the function in any way. i.e. if the only thing the decorator does is perform a side effect like adding the function to a some dictionary, prints something, or fires a missile.

the function needs to be updated with the result from the decorator in order for it to also be transformed. so the second case would actually need to be:
def f():
    pass
f = decorator(f)

here is my python session where I tested this:
>>> def dec(func):
...  print('side effect')
...  def newFunc(*args, **kvargs): return func(*args, **kvargs) + 1
...  return newFunc
...
>>> def f(): return 1
...
>>> f()
1
>>> dec(f)
side effect
<function dec.<locals>.newFunc at 0x000002113ADE7EA0>
>>> f()
1
>>> @dec
... def g(): return 1
...
side effect
>>> g()
2
>>> f = dec(f)
side effect
>>> f()
2

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Dragonlee via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Dragonlee via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector

Reply via email to