當前位置: 首頁>>代碼示例>>Python>>正文


Python typing.Any方法代碼示例

本文整理匯總了Python中typing.Any方法的典型用法代碼示例。如果您正苦於以下問題:Python typing.Any方法的具體用法?Python typing.Any怎麽用?Python typing.Any使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在typing的用法示例。


在下文中一共展示了typing.Any方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def __init__(
        self,
        long_name,
        short_name=None,
        flags=0,
        description=None,
        default=None,
        value_name="...",
    ):  # type: (str, Optional[str], int, Optional[str], Any, str) -> None
        self._validate_flags(flags)

        super(Option, self).__init__(long_name, short_name, flags, description)

        self._value_name = value_name

        if self.is_multi_valued():
            self._default = []
        else:
            self._default = None

        if self.accepts_value() or default is not None:
            self.set_default(default) 
開發者ID:sdispater,項目名稱:clikit,代碼行數:24,代碼來源:option.py

示例2: set_default

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def set_default(self, default=None):  # type: (Any) -> None
        if not self.accepts_value():
            raise ValueError(
                "Cannot set a default value when using the flag VALUE_NONE."
            )

        if self.is_multi_valued():
            if default is None:
                default = []
            elif not isinstance(default, list):
                raise ValueError(
                    "The default value of a multi-valued option must be a list. "
                    "Got: {}".format(type(default))
                )

        self._default = default 
開發者ID:sdispater,項目名稱:clikit,代碼行數:18,代碼來源:option.py

示例3: _create_builder_for_elements

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def _create_builder_for_elements(
        self, elements, base_format=None
    ):  # type: (List[Any], Optional[ArgsFormat]) -> ArgsFormatBuilder
        from .args_format_builder import ArgsFormatBuilder

        builder = ArgsFormatBuilder(base_format)

        for element in elements:
            if isinstance(element, CommandName):
                builder.add_command_name(element)
            elif isinstance(element, CommandOption):
                builder.add_command_option(element)
            elif isinstance(element, Option):
                builder.add_option(element)
            elif isinstance(element, Argument):
                builder.add_argument(element)

        return builder 
開發者ID:sdispater,項目名稱:clikit,代碼行數:20,代碼來源:args_format.py

示例4: parse_boolean

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def parse_boolean(value, nullable=True):  # type: (Any, bool) -> Optional[bool]
    if nullable and (value is None or value == "null"):
        return

    if isinstance(value, bool):
        return value

    if isinstance(value, int):
        value = str(value)

    if isinstance(value, basestring):
        if not value:
            return False

        if value in {"false", "0", "no", "off"}:
            return False

        if value in {"true", "1", "yes", "on"}:
            return True

    raise ValueError('The value "{}" cannot be parsed as boolean.'.format(value)) 
開發者ID:sdispater,項目名稱:clikit,代碼行數:23,代碼來源:string.py

示例5: apply_filter

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def apply_filter(object_id: str, search_props: Dict[str, Any],
                 triples: Graph, session: scoped_session) -> bool:
    """Check whether objects has properties with query values or not.
    :param object_id: Id of the instance.
    :param search_props: Dictionary of query parameters with property id and values.
    :param triples: All triples.
    :param session: sqlalchemy scoped session.
    :return: True if the instance has properties with given values, False otherwise.
    """
    for prop in search_props:
        # For nested properties
        if isinstance(search_props[prop], dict):
            data = session.query(triples).filter(
                triples.GraphIII.subject == object_id, triples.GraphIII.predicate == prop).one()
            if apply_filter(data.object_, search_props[prop], triples, session) is False:
                return False
        else:
            data = session.query(triples).filter(
                triples.GraphIIT.subject == object_id, triples.GraphIIT.predicate == prop).one()
            terminal = session.query(Terminal).filter(
                Terminal.id == data.object_).one()
            if terminal.value != search_props[prop]:
                return False
    return True 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:26,代碼來源:crud_helpers.py

示例6: insert_single

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def insert_single(object_: Dict[str, Any], session: scoped_session) -> Any:
    """Insert instance of classes with single objects.
    :param object_: object to be inserted
    :param session: sqlalchemy scoped session
    :return:

    Raises:
        ClassNotFound: If `type_` does not represt a valid/defined RDFClass.
        Instance: If an Instance of type `type_` already exists.

    """
    try:
        rdf_class = session.query(RDFClass).filter(
            RDFClass.name == object_["@type"]).one()
    except NoResultFound:
        raise ClassNotFound(type_=object_["@type"])

    try:
        session.query(Instance).filter(
            Instance.type_ == rdf_class.id).all()[-1]
    except (NoResultFound, IndexError, ValueError):
        return insert(object_, session=session)

    raise InstanceExists(type_=rdf_class.name) 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:26,代碼來源:crud.py

示例7: set_authentication

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def set_authentication(application: Flask, authentication: bool) -> Iterator:
    """
    Set the whether API needs to be authenticated or not (before it is run in main.py).

    :param application: Flask app object
            <flask.app.Flask>
    :param authentication : Bool. API Auth needed or not
            <bool>


    Raises:
        TypeError: If `authentication` is not a boolean value.

    """
    if not isinstance(authentication, bool):
        raise TypeError("Authentication flag must be of type <bool>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.authentication_ = authentication
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:23,代碼來源:utils.py

示例8: set_api_name

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def set_api_name(application: Flask, api_name: str) -> Iterator:
    """
    Set the server name or EntryPoint for the app (before it is run in main.py).
    :param application: Flask app object
            <flask.app.Flask>
    :param api_name : API/Server name or EntryPoint
            <str>

    Raises:
        TypeError: If `api_name` is not a string.

    """
    if not isinstance(api_name, str):
        raise TypeError("The api_name is not of type <str>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.api_name = api_name
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:21,代碼來源:utils.py

示例9: set_page_size

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def set_page_size(application: Flask, page_size: int) -> Iterator:
    """
    Set the page_size of a page view.
    :param application: Flask app object
            <flask.app.Flask>
    :param page_size : Number of maximum elements a page can contain
            <int>

    Raises:
        TypeError: If `page_size` is not an int.

    """
    if not isinstance(page_size, int):
        raise TypeError("The page_size is not of type <int>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.page_size = page_size
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:21,代碼來源:utils.py

示例10: set_pagination

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def set_pagination(application: Flask, paginate: bool) -> Iterator:
    """
    Enable or disable pagination.
    :param application: Flask app object
            <flask.app.Flask>
    :param paginate : Pagination enabled or not
            <bool>

    Raises:
        TypeError: If `paginate` is not a bool.

    """
    if not isinstance(paginate, bool):
        raise TypeError("The CLI argument 'pagination' is not of type <bool>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.paginate = paginate
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:21,代碼來源:utils.py

示例11: set_doc

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def set_doc(application: Flask, APIDOC: HydraDoc) -> Iterator:
    """
    Set the API Documentation for the app (before it is run in main.py).
    :param application: Flask app object
            <flask.app.Flask>
    :param APIDOC : Hydra Documentation object
            <hydra_python_core.doc_writer.HydraDoc>

    Raises:
        TypeError: If `APIDOC` is not an instance of `HydraDoc`.

    """
    if not isinstance(APIDOC, HydraDoc):
        raise TypeError(
            "The API Doc is not of type <hydra_python_core.doc_writer.HydraDoc>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.doc = APIDOC
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:22,代碼來源:utils.py

示例12: set_hydrus_server_url

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def set_hydrus_server_url(application: Flask, server_url: str) -> Iterator:
    """
    Set the server URL for the app (before it is run in main.py).
    :param application: Flask app object
            <flask.app.Flask>
    :param server_url : Server URL
            <str>

    Raises:
        TypeError: If the `server_url` is not a string.

    """
    if not isinstance(server_url, str):
        raise TypeError("The server_url is not of type <str>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.hydrus_server_url = server_url
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:21,代碼來源:utils.py

示例13: set_session

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def set_session(application: Flask, DB_SESSION: scoped_session) -> Iterator:
    """
    Set the Database Session for the app before it is run in main.py.
    :param application: Flask app object
            <flask.app.Flask>
    :param DB_SESSION: SQLalchemy Session object
            <sqlalchemy.orm.session.Session>

    Raises:
        TypeError: If `DB_SESSION` is not an instance of `scoped_session` or `Session`.

    """
    if not isinstance(DB_SESSION, scoped_session) and not isinstance(
            DB_SESSION, Session):
        raise TypeError(
            "The API Doc is not of type <sqlalchemy.orm.session.Session> or"
            " <sqlalchemy.orm.scoping.scoped_session>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.dbsession = DB_SESSION
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:24,代碼來源:utils.py

示例14: get_link_props_for_multiple_objects

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def get_link_props_for_multiple_objects(path: str,
                                        object_list: List[Dict[str, Any]]
                                        ) -> Tuple[List[Dict[str, Any]], bool]:
    """
    Get link_props of multiple objects.
    :param path: Path of the collection or non-collection class.
    :param object_list: List of objects being inserted.
    :return: List of link properties processed with the help of get_link_props.
    """
    link_prop_list = list()
    for object_ in object_list:
        link_props, type_check = get_link_props(path, object_)
        if type_check is True:
            link_prop_list.append(link_props)
        else:
            return [], False
    return link_prop_list, True 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:19,代碼來源:helpers.py

示例15: __eq__

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Any [as 別名]
def __eq__(self, rhs: t.Any) -> Predicate:
        """
        Test the value for equality.
        >>> var('f1') == 42

        :param rhs: The value to compare against. It can either be a plain
         value or a Var instance which points to another field on the value
         that will be used during evaluation.
        :returns: A predicate of this comparison.
        """
        rhs_curried = _curry_rhs(rhs)
        return self._build_predicate(
            lambda lhs, value: lhs == rhs_curried(value),
            Operation.EQ,
            (self._path, freeze(rhs))
        ) 
開發者ID:pcah,項目名稱:python-clean-architecture,代碼行數:18,代碼來源:predicate.py


注:本文中的typing.Any方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。