[Python-Dev] PEP 559 - built-in noop()

Oleg Broytman phd at phdru.name
Sat Sep 9 17:38:46 EDT 2017


On Sat, Sep 09, 2017 at 02:33:18PM -0700, Victor Stinner <victor.stinner at gmail.com> wrote:
> I was able to find a real keyboard, so here is a more complete code:
> ---
> class Noop:
>     def __call__(self, *args, **kw):
>         return self
>     def __enter__(self, *args, **kw):
>         return self
>     def __exit__(self, *args):
>         return
>     def __repr__(self):
>         return 'nope'
> ---
> 
> Example:
> ---
> noop = Noop()
> print(noop)
> print(noop())
> with noop() as nope:
>     print(nope)
> with noop as well:
>     print(well)
> ---
> 
> Output:
> ---
> nope
> nope
> nope
> nope
> ---
> 
> IHMO the real question is if we need a Noop.nope() method?

   Yep. It must return self so one can chain as many calls as she wants.

> Victor

Oleg.
-- 
     Oleg Broytman            http://phdru.name/            phd at phdru.name
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-Dev mailing list