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


Python typing.Literal方法代码示例

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


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

示例1: open_bytes

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def open_bytes(self, mode='rb'):
    # type: (Text) -> ContextManager[BinaryIO]
    """Return a context manager for opening the file in binary mode.

    Args:
      mode: The mode to open the file in. The "b" mode is implicit if not
        already present. It must not have the "t" flag.

    Returns:
      Context manager that yields an open file.

    Raises:
      ValueError: if invalid inputs are provided.
    """
    if 't' in mode:
      raise ValueError('Invalid mode {!r}: "t" flag not allowed when opening '
                       'file in binary mode'.format(mode))
    if 'b' not in mode:
      mode += 'b'
    cm = self._open(mode, encoding=None, errors=None)  # type: ContextManager[BinaryIO]
    return cm

  # TODO(b/123775699): Once pytype supports typing.Literal, use overload and
  # Literal to express more precise return types and remove the type comments in
  # open_text and open_bytes. 
开发者ID:abseil,项目名称:abseil-py,代码行数:27,代码来源:absltest.py

示例2: request

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def request(
				self, path: str,
				args: ty.Sequence[str] = [], *,
				opts: ty.Mapping[str, str] = {},
				decoder: str = "none",
				stream: bool = False,
				offline: bool = False,
				return_result: ty.Literal[False],
				auth: auth_t = None,
				cookies: cookies_t = None,
				data: reqdata_sync_t = None,
				headers: headers_t = None,
				timeout: timeout_t = None
		) -> None:
			... 
开发者ID:ipfs-shipyard,项目名称:py-ipfs-http-client,代码行数:17,代码来源:http_common.py

示例3: get_encoding

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def get_encoding(name: ty.Literal["none"]) -> Dummy:
		... 
开发者ID:ipfs-shipyard,项目名称:py-ipfs-http-client,代码行数:4,代码来源:encoding.py

示例4: __getitem__

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def __getitem__(cls, values):
                if not isinstance(values, tuple):
                    values = (values,)
                return type('Literal_', (Literal,), dict(__args__=values)) 
开发者ID:theislab,项目名称:scanpy,代码行数:6,代码来源:_compat.py

示例5: read_tsv

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def read_tsv(
    path: Path, as_dict: Literal[False], **kwargs
) -> Generator[List[str], None, None]:
    ... 
开发者ID:ding-lab,项目名称:CharGer,代码行数:6,代码来源:io.py

示例6: test_literal_type_typing

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def test_literal_type_typing(self):
        self.flakes("""
        from typing import Literal

        def f(x: Literal['some string']) -> None:
            return None
        """) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:9,代码来源:test_type_annotations.py

示例7: test_literal_type_typing_extensions

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def test_literal_type_typing_extensions(self):
        self.flakes("""
        from typing_extensions import Literal

        def f(x: Literal['some string']) -> None:
            return None
        """) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:9,代码来源:test_type_annotations.py

示例8: test_literal_type_some_other_module

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def test_literal_type_some_other_module(self):
        """err on the side of false-negatives for types named Literal"""
        self.flakes("""
        from my_module import compat
        from my_module.compat import Literal

        def f(x: compat.Literal['some string']) -> None:
            return None
        def g(x: Literal['some string']) -> None:
            return None
        """) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:13,代码来源:test_type_annotations.py

示例9: test_literal_union_type_typing

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def test_literal_union_type_typing(self):
        self.flakes("""
        from typing import Literal

        def f(x: Literal['some string', 'foo bar']) -> None:
            return None
        """) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:9,代码来源:test_type_annotations.py

示例10: __getitem__

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def __getitem__(cls, values):
                if not isinstance(values, tuple):
                    values = (values,)
                return type("Literal_", (Literal,), dict(__args__=values)) 
开发者ID:theislab,项目名称:anndata,代码行数:6,代码来源:__init__.py

示例11: test_is_literal_with_literal

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def test_is_literal_with_literal():
    from typing import Literal

    assert is_literal(Literal["A", "B"]) 
开发者ID:konradhalas,项目名称:dacite,代码行数:6,代码来源:test_types.py

示例12: test_is_instance_with_literal_and_matching_type

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def test_is_instance_with_literal_and_matching_type():
    from typing import Literal

    assert is_instance("A", Literal["A", "B"]) 
开发者ID:konradhalas,项目名称:dacite,代码行数:6,代码来源:test_types.py

示例13: test_is_instance_with_literal_and_not_matching_type

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def test_is_instance_with_literal_and_not_matching_type():
    from typing import Literal

    assert not is_instance("C", Literal["A", "B"]) 
开发者ID:konradhalas,项目名称:dacite,代码行数:6,代码来源:test_types.py

示例14: test_is_instance_with_optional_literal_and_matching_type

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def test_is_instance_with_optional_literal_and_matching_type():
    from typing import Literal

    assert is_instance("A", Optional[Literal["A", "B"]]) 
开发者ID:konradhalas,项目名称:dacite,代码行数:6,代码来源:test_types.py

示例15: test_is_instance_with_optional_literal_and_not_matching_type

# 需要导入模块: import typing [as 别名]
# 或者: from typing import Literal [as 别名]
def test_is_instance_with_optional_literal_and_not_matching_type():
    from typing import Literal

    assert not is_instance("C", Optional[Literal["A", "B"]]) 
开发者ID:konradhalas,项目名称:dacite,代码行数:6,代码来源:test_types.py


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