当前位置: 首页>>代码示例>>Python>>正文


Python attr.Attribute方法代码示例

本文整理汇总了Python中attr.Attribute方法的典型用法代码示例。如果您正苦于以下问题:Python attr.Attribute方法的具体用法?Python attr.Attribute怎么用?Python attr.Attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在attr的用法示例。


在下文中一共展示了attr.Attribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_attribute_section

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def add_attribute_section(process, placeholder="{{attributes}}"):
    data_type = ":class:`attr.Attribute`"

    fmt_vars = []

    for vname, var in variables_dict(process).items():
        var_header = f"{vname} : {data_type}"
        var_content = textwrap.indent(var_details(var, max_line_length=62), " " * 4)

        fmt_vars.append(f"{var_header}\n{var_content}")

    fmt_section = textwrap.indent(
        "Attributes\n" "----------\n" + "\n".join(fmt_vars), " " * 4
    )

    current_doc = process.__doc__ or ""

    if placeholder in current_doc:
        new_doc = current_doc.replace(placeholder, fmt_section[4:])
    else:
        new_doc = f"{current_doc.rstrip()}\n\n{fmt_section}\n"

    return new_doc 
开发者ID:benbovy,项目名称:xarray-simlab,代码行数:25,代码来源:formatting.py

示例2: __setattr__

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def __setattr__(self, name, value):
        """Mimic attr.s(frozen=True) behaviour but allow for attributes
        to be initialized after class instantiation.

        Useful when you would like a class to be immutable after a
        certain action, such as a save to a database.

        Any attributes created with ``attr.ib(init=False)`` or are
        initially set to ``None`` in ``__init__()`` are allowed to have
        their values be set once after initialization. Any other
        attributes with initial values set are immediately frozen upon
        initialization.

        **Note**: Obviously, this doesn't stop anyone from setting the
        uninitialized attributes before you've set it yourself.
        Hopefully, you've got responsibile users.

        Raises:
            :class:`attr.exceptions.FronzenInstanceError`: if a frozen
                attribute is set
        """
        current_value = getattr(self, name, None)
        if current_value is None or isinstance(current_value, attr.Attribute):
            super().__setattr__(name, value)
        else:
            raise attr.exceptions.FrozenInstanceError() 
开发者ID:COALAIP,项目名称:pycoalaip,代码行数:28,代码来源:utils.py

示例3: create_attribute

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def create_attribute():
    return attr.Attribute(
        name='x',
        default=None,
        validator=None,
        repr=True,
        cmp=None,
        eq=True,
        order=False,
        hash=True,
        init=True) 
开发者ID:weaveworks,项目名称:grafanalib,代码行数:13,代码来源:test_validators.py

示例4: _expand_responses_validator

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def _expand_responses_validator(self, _: "attr.Attribute[str]", value: str) -> None:
        if value in ("all", ""):
            return
        raw_codes = value.split(",")
        for raw_code in raw_codes:
            try:
                int(raw_code)
            except ValueError:
                raise ValueError(
                    "expandResponses must be either 'all' or "
                    f"comma-separated list of http codes, got '{raw_code}'"
                )

    # noinspection PyUnresolvedReferences 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:16,代码来源:ui_settings.py

示例5: _json_sample_expand_level_validator

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def _json_sample_expand_level_validator(
        self, _: "attr.Attribute[Union[int, str]]", value: Union[int, str]
    ) -> None:
        if isinstance(value, str) and value != "all":
            raise ValueError(
                f"jsonSampleExpandLevel must be either 'all' or integer, got '{value}'"
            ) 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:9,代码来源:ui_settings.py

示例6: _bg_color_validator

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def _bg_color_validator(self, _: "attr.Attribute[str]", value: str) -> None:
        if not HEX_COLOR_REGEX.match(value):
            raise ValueError("bg_color must be valid HEX color")

    # noinspection PyUnresolvedReferences 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:7,代码来源:ui_settings.py

示例7: _text_color_validator

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def _text_color_validator(self, _: "attr.Attribute[str]", value: str) -> None:
        if not HEX_COLOR_REGEX.match(value):
            raise ValueError("text_color must be valid HEX color")

    # noinspection PyUnresolvedReferences 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:7,代码来源:ui_settings.py

示例8: _nav_bg_color_validator

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def _nav_bg_color_validator(
        self, _: "attr.Attribute[Optional[str]]", value: Optional[str]
    ) -> None:
        if value is not None and not HEX_COLOR_REGEX.match(value):
            raise ValueError("nav_bg_color must be valid HEX color") 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:7,代码来源:ui_settings.py

示例9: _nav_hover_bg_color_validator

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def _nav_hover_bg_color_validator(
        self, _: "attr.Attribute[Optional[str]]", value: Optional[str]
    ) -> None:
        if value is not None and not HEX_COLOR_REGEX.match(value):
            raise ValueError("nav_hover_bg_color must be valid HEX color") 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:7,代码来源:ui_settings.py

示例10: _nav_hover_text_color_validator

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def _nav_hover_text_color_validator(
        self, _: "attr.Attribute[Optional[str]]", value: Optional[str]
    ) -> None:
        if value is not None and not HEX_COLOR_REGEX.match(value):
            raise ValueError("nav_hover_text_color must be valid HEX color") 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:7,代码来源:ui_settings.py

示例11: _nav_accent_color_validator

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def _nav_accent_color_validator(
        self, _: "attr.Attribute[Optional[str]]", value: Optional[str]
    ) -> None:
        if value is not None and not HEX_COLOR_REGEX.match(value):
            raise ValueError("nav_accent_color must be valid HEX color") 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:7,代码来源:ui_settings.py

示例12: _get_attr_from_attrs

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def _get_attr_from_attrs(attrs: Iterable[Attribute], name: str) -> Attribute:
    attrs = [a for a in attrs if a.name == name]
    return attrs[0] 
开发者ID:justanr,项目名称:marshmallow-annotations,代码行数:5,代码来源:attrs.py

示例13: simple_attr

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
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,
    ) 
开发者ID:python-attrs,项目名称:attrs,代码行数:30,代码来源:utils.py

示例14: get_units

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def get_units(field: attr.Attribute) -> str:
    return field.metadata.get(UNIT_SUFFIX, "") 
开发者ID:corrscope,项目名称:corrscope,代码行数:4,代码来源:config.py

示例15: test_add_attribute_section

# 需要导入模块: import attr [as 别名]
# 或者: from attr import Attribute [as 别名]
def test_add_attribute_section():
    # For testing, autodoc is set to False to avoid redundancy
    expected = """My process

    Attributes
    ----------
    var1 : :class:`attr.Attribute`
        A variable

        Variable properties:

        - type : ``variable``
        - intent : ``in``
        - dimensions : ('x',)

    var2 : :class:`attr.Attribute`
        No description given

        Variable properties:

        - type : ``variable``
        - intent : ``in``
        - dimensions : ()
    """

    assert add_attribute_section(WithoutPlaceHolder).strip() == expected.strip()
    assert add_attribute_section(WithPlaceholder).strip() == expected.strip() 
开发者ID:benbovy,项目名称:xarray-simlab,代码行数:29,代码来源:test_formatting.py


注:本文中的attr.Attribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。