>
> BTW In your defaultdict-example there is a known_classes0 which is not
> part of the code. And it's not clear how that (again overcomplicated) code
> is better than a regular defaultdict(dict).
>
>
function known_classes0 just returns handmade dictionary of known classes
like c, p, g,
| ast.walk chaotic order
It certainly has its drawbacks. However, it can help to shift programmers
mind more towards sets and pure functions and away from procedural way of
thinking.
As you can see in given example I had to operate on ClassDefs and
FunctionDefs in more strict ordering, so
What I was hoping to share in my code example was not about generators. It
is true that python2 doesn't allow to return values from generator
functions, but plain return statement is allowed and is equivalent to
`return None`.
Generators that I used in my code were just leftovers of my
Am Donnerstag, 14. Dezember 2017 11:05:46 UTC+1 schrieb Edward K. Ream:
In our code, bool(node) is always True, so this comment is a bit off the
> mark.
>
Well that's a chance to fix this. You are also free to enhance the
check.Checking expliciet for None is popular with other DOM-libs.
On Thu, Dec 14, 2017 at 3:22 AM, 'Marcel Franke' via leo-editor <
leo-editor@googlegroups.com> wrote:
>
>
> Am Mittwoch, 13. Dezember 2017 22:28:50 UTC+1 schrieb Edward K. Ream:
>
> def a_generator():
>> if 0:
>> yield 'abc' # Makes the function a generator
>> return None
>>
>
>
Am Mittwoch, 13. Dezember 2017 22:28:50 UTC+1 schrieb Edward K. Ream:
def a_generator():
> if 0:
> yield 'abc' # Makes the function a generator
> return None
>
This only works with Python 3. Python 2 does not support mixing return and
yield.
It's also overcomplicated.
On Wednesday, December 13, 2017 at 3:28:50 PM UTC-6, Edward K. Ream wrote:
There are several coding patterns in Vitalije's prototype that deserve
> mention.
>
*Generators as predicates*
>
> Vitalije's prototype (as modified in leoCheck.py) contains this:
>
> for node in ast.walk(root):
>
There are several coding patterns in Vitalije's prototype that deserve
mention.
*Generators*
['abc'].extend(None) throws a TypeError. However, the following works:
def a_generator():
if 0:
yield 'abc' # Makes the function a generator
return None
aList = ['abc']