示例#1
0
def simple_attr(
    name,
    default=NOTHING,
    validator=None,
    repr=True,
    eq=True,
    hash=None,
    init=True,
    converter=None,
    kw_only=False,
    inherited=False,
):
    """
    Return an attribute with a name and no other bells and whistles.
    """
    return Attribute(
        name=name,
        default=default,
        validator=validator,
        repr=repr,
        cmp=None,
        eq=eq,
        hash=hash,
        init=init,
        converter=converter,
        kw_only=kw_only,
        inherited=inherited,
    )
示例#2
0
def adapted_fields(type) -> List[Attribute]:
    """Return the attrs format of `fields()` for attrs and dataclasses."""
    if is_dataclass(type):
        return [
            Attribute(
                attr.name,
                attr.default
                if attr.default is not MISSING
                else (
                    Factory(attr.default_factory)
                    if attr.default_factory is not MISSING
                    else NOTHING
                ),
                None,
                True,
                None,
                True,
                attr.init,
                True,
                type=attr.type,
            )
            for attr in dataclass_fields(type)
        ]
    else:
        return attrs_fields(type)
示例#3
0
文件: base.py 项目: jayvdb/githubcap
    def _from_dict_value(cls, attribute_type: attr.Attribute,
                         value: typing.Any) -> typing.Any:
        """Translate value to it's actual representation based on resource type defined."""
        # pylint: disable=protected-access
        if attribute_type == datetime:
            return parse_datetime(value)
        elif issubclass(attribute_type, GitHubCapEnum):
            return attribute_type.from_value(value)
        elif issubclass(attribute_type, GitHubBase):
            return attribute_type.from_dict(value)
        elif '_gorg' in attribute_type.__dict__ and attribute_type._gorg == typing.List:
            assert len(attribute_type.__args__) == 1,\
                "Type defined multiple types: {!r}".format(attribute_type)  # Ignore B101
            return list(
                cls._from_dict_value(attribute_type.__args__[0], item)
                for item in value)

        return value
示例#4
0
def simple_attr(name, default=NOTHING, validator=None, repr=True,
                cmp=True, hash=True, init=True):
    """
    Return an attribute with a name and no other bells and whistles.
    """
    return Attribute(
        name=name, default=default, validator=validator, repr=repr,
        cmp=cmp, hash=hash, init=init
    )
示例#5
0
def simple_attr(name,
                default=NOTHING,
                validator=None,
                no_repr=False,
                no_cmp=False,
                no_hash=False,
                no_init=False):
    """
    Return an attribute with a name and no other bells and whistles.
    """
    return Attribute(name=name,
                     default=default,
                     validator=validator,
                     no_repr=no_repr,
                     no_cmp=no_cmp,
                     no_hash=no_hash,
                     no_init=no_init)
示例#6
0
def make_attribute(name, **kwargs):
    kwargs = {**FIELD_DEFAULTS, **kwargs}
    return Attribute(name=name, **kwargs)