Exemple #1
0
    def required_attributes(cls):
        """

        Figures out which attributes, if any, were declared as
        RequiredAttribute instances.

        :returns: Dictionary.  The keys in this dictionary are the names of the
        attributes that are required.  For each attribute, the value either
        `None` or a type object.

        """

        required_attributes = {}

        for clazz in extract_classes(cls):
            for key,value in clazz.__dict__.items():
                if isinstance(value, cls.RequiredAttribute):
                    required_attributes[key] = value.required_type

        return required_attributes
Exemple #2
0
    def required_attributes(cls):
        """

        Figures out which attributes, if any, were declared as
        RequiredAttribute instances.

        :returns: Dictionary.  The keys in this dictionary are the names of the
        attributes that are required.  For each attribute, the value either
        `None` or a type object.

        """

        required_attributes = {}

        for clazz in extract_classes(cls):
            for key, value in clazz.__dict__.items():
                if isinstance(value, cls.RequiredAttribute):
                    required_attributes[key] = value.required_type

        return required_attributes
Exemple #3
0
def extract_classes(clazz):
    """

    Find all parent classes, anywhere in the inheritance tree.

    :param clazz: class, the thing to crawl through 
    
    Returns a list of all base classes in the inheritance tree

    """

    extracted = [clazz]

    for base in clazz.__bases__:
        extracted += extract_classes(base)

    # no need to include 'object'
    if object in extracted:
        extracted.remove(object)

    return dedupe_list(extracted, preserve_order=True)
Exemple #4
0
def extract_classes(clazz):
    """

    Find all parent classes, anywhere in the inheritance tree.

    :param clazz: class, the thing to crawl through 
    
    Returns a list of all base classes in the inheritance tree

    """

    extracted = [clazz]

    for base in clazz.__bases__:
        extracted += extract_classes(base)

    # no need to include 'object'
    if object in extracted:
        extracted.remove(object)

    return dedupe_list(extracted, preserve_order=True)