Movatterモバイル変換


[0]ホーム

URL:


[Python-ideas] Another use case for the 'lazy' (aka 'delayed') keyword

Michel Desmoulindesmoulinmichel at gmail.com
Tue Feb 28 09:46:27 EST 2017


Le 28/02/2017 à 13:47, Markus Meskanen a écrit :>     You don't need list comprehension, you can use a for loop.>>     You don't need upacking you can use indexing.>>     And you don't need lazy, it's just convenient.>>> With this sole argument you can add almost anything to the language as> long as it has at least one use case where it's better than existing> tools. I'm not against the lazy proposal in general, but attempting to> justify a new keyword to replace this is just silly to me:>> class Config(dict):>     def lazy_get(self, key, callable=None):>         if key in self:>             return self[key]>         return callable(key)With this sole argument you can reject await / async because we could doit with yield from and decorator.With this solve argument you can reject comprehension because we havemap and filter.With this solve argument you can reject defauldict because we can codeone ourself.I mean come on, a decorator is just:@decoratordef decorated():Instead ofdecorated = decorator(decorated)It's just convenience and elegance.The sweet spot for lazy is a use case where you can't easily modify thecode to get your getter and setter. You example again makes theassumption you can easily add such a wrapper. But if you can't, then youhave to import it and wrap the config object in every module using it.Test all that. Ensure you don't pass the wrapper by accident tosomething that would break on it, etc.And how many time do you have to do that ?You will write your wrapper for lists ? And tuples ?And will you test those ? document those ? Explain to others that to geta callable, you need to pass a callable returning a callable ?Then again for your next project or you do a library with all the stuffit implies ?It's neither convenient nor elegant.lazy is not only practical, but it's also beautiful. It reads well. Itsolves a problem we all have on a regular basis.Yes we can live without it. I mean, Python is already incrediblyconvenient, of course whatever we suggest now is going to be a cherry ontop of the language cake.And yes I got a big mouth because it's a lot of work to implement it andit's work I'm not capable to do since I can't code in C to save my life.Does it removes the merits from lazy ?Wouldn't you like it to just be able to drop "lazy" in your next 3.7 code ?


More information about the Python-ideasmailing list

[8]ページ先頭

©2009-2026 Movatter.jp