當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。