d0c-s4vage/pfp

Don't cause an exception in _pfp__children

Open

#32 创建于 2016年3月3日

在 GitHub 查看
 (1 评论) (0 反应) (1 负责人)Python (37 fork)github user discovery
enhancementgood first issue

仓库指标

Star
 (203 star)
PR 合并指标
 (PR 指标待抓取)

描述

I don't know if this would break something but wouldn't be better to have every element default to have an attribute _pfp__children equal to an empty list?

This way when write something like obj._pfp__children in say, traversing the DOM's graph (DFS or alike) you don't have to worry about exceptions and the code is more succinct.

Right now I am using an auxiliary function like:

def has_children(n):
    """ Returns boolean """
    try:
        n._pfp__children
        return True

    except AttributeError:
        return False

but it looks cumbersome and feels more natural to return an empty list to the question "give me a list containing your children"

Anyway, awesome work man :+1:

贡献者指南