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


Python typing.SupportsInt方法代码示例

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


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

示例1: _to_str

# 需要导入模块: import typing [as 别名]
# 或者: from typing import SupportsInt [as 别名]
def _to_str(size, suffixes, base):
    # type: (SupportsInt, Iterable[Text], int) -> Text
    try:
        size = int(size)
    except ValueError:
        raise TypeError("filesize requires a numeric value, not {!r}".format(size))
    if size == 1:
        return "1 byte"
    elif size < base:
        return "{:,} bytes".format(size)

    # TODO (dargueta): Don't rely on unit or suffix being defined in the loop.
    for i, suffix in enumerate(suffixes, 2):  # noqa: B007
        unit = base ** i
        if size < unit:
            break
    return "{:,.1f} {}".format((base * size / unit), suffix) 
开发者ID:PyFilesystem,项目名称:pyfilesystem2,代码行数:19,代码来源:filesize.py

示例2: traditional

# 需要导入模块: import typing [as 别名]
# 或者: from typing import SupportsInt [as 别名]
def traditional(size):
    # type: (SupportsInt) -> Text
    """Convert a filesize in to a string (powers of 1024, JDEC prefixes).

    In this convention, ``1024 B = 1 KB``.

    This is the format that was used to display the size of DVDs
    (*700 MB* meaning actually about *734 003 200 bytes*) before
    standardisation of IEC units among manufacturers, and still
    used by **Windows** to report the storage capacity of hard
    drives (*279.4 GB* meaning *279.4 × 1024³ bytes*).

    Arguments:
        size (int): A file size.

    Returns:
        `str`: A string containing an abbreviated file size and units.

    Example:
        >>> filesize.traditional(30000)
        '29.3 KB'

    """
    return _to_str(size, ("KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"), 1024) 
开发者ID:PyFilesystem,项目名称:pyfilesystem2,代码行数:26,代码来源:filesize.py

示例3: binary

# 需要导入模块: import typing [as 别名]
# 或者: from typing import SupportsInt [as 别名]
def binary(size):
    # type: (SupportsInt) -> Text
    """Convert a filesize in to a string (powers of 1024, IEC prefixes).

    In this convention, ``1024 B = 1 KiB``.

    This is the format that has gained adoption among manufacturers
    to avoid ambiguity regarding size units, since it explicitly states
    using a binary base (*KiB = kibi bytes = kilo binary bytes*).
    This format is notably being used by the **Linux** kernel (see
    ``man 7 units``).

    Arguments:
        int (size): A file size.

    Returns:
        `str`: A string containing a abbreviated file size and units.

    Example:
        >>> filesize.binary(30000)
        '29.3 KiB'

    """
    return _to_str(size, ("KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"), 1024) 
开发者ID:PyFilesystem,项目名称:pyfilesystem2,代码行数:26,代码来源:filesize.py

示例4: decimal

# 需要导入模块: import typing [as 别名]
# 或者: from typing import SupportsInt [as 别名]
def decimal(size):
    # type: (SupportsInt) -> Text
    """Convert a filesize in to a string (powers of 1000, SI prefixes).

    In this convention, ``1000 B = 1 kB``.

    This is typically the format used to advertise the storage
    capacity of USB flash drives and the like (*256 MB* meaning
    actually a storage capacity of more than *256 000 000 B*),
    or used by **Mac OS X** since v10.6 to report file sizes.

    Arguments:
        int (size): A file size.

    Returns:
        `str`: A string containing a abbreviated file size and units.

    Example:
        >>> filesize.decimal(30000)
        '30.0 kB'

    """
    return _to_str(size, ("kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"), 1000) 
开发者ID:PyFilesystem,项目名称:pyfilesystem2,代码行数:25,代码来源:filesize.py

示例5: _parse_letter_version

# 需要导入模块: import typing [as 别名]
# 或者: from typing import SupportsInt [as 别名]
def _parse_letter_version(
    letter,  # type: str
    number,  # type: Union[str, bytes, SupportsInt]
):
    # type: (...) -> Optional[Tuple[str, int]]

    if letter:
        # We consider there to be an implicit 0 in a pre-release if there is
        # not a numeral associated with it.
        if number is None:
            number = 0

        # We normalize any letters to their lower case form
        letter = letter.lower()

        # We consider some words to be alternate spellings of other words and
        # in those cases we want to normalize the spellings to our preferred
        # spelling.
        if letter == "alpha":
            letter = "a"
        elif letter == "beta":
            letter = "b"
        elif letter in ["c", "pre", "preview"]:
            letter = "rc"
        elif letter in ["rev", "r"]:
            letter = "post"

        return letter, int(number)
    if not letter and number:
        # We assume if we are given a number, but we are not given a letter
        # then this is using the implicit post release syntax (e.g. 1.0-1)
        letter = "post"

        return letter, int(number)

    return None 
开发者ID:pypa,项目名称:pipenv,代码行数:38,代码来源:version.py

示例6: test_supports_int

# 需要导入模块: import typing [as 别名]
# 或者: from typing import SupportsInt [as 别名]
def test_supports_int(self):
        assert issubclass(int, typing.SupportsInt)
        assert not issubclass(str, typing.SupportsInt) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_typing.py

示例7: _parse_letter_version

# 需要导入模块: import typing [as 别名]
# 或者: from typing import SupportsInt [as 别名]
def _parse_letter_version(
    letter: str,
    number: Union[str, bytes, SupportsInt],
) -> Optional[Tuple[str, int]]:

    if letter:
        # We consider there to be an implicit 0 in a pre-release if there is
        # not a numeral associated with it.
        if number is None:
            number = 0

        # We normalize any letters to their lower case form
        letter = letter.lower()

        # We consider some words to be alternate spellings of other words and
        # in those cases we want to normalize the spellings to our preferred
        # spelling.
        if letter == "alpha":
            letter = "a"
        elif letter == "beta":
            letter = "b"
        elif letter in ["c", "pre", "preview"]:
            letter = "rc"
        elif letter in ["rev", "r"]:
            letter = "post"

        return letter, int(number)
    if not letter and number:
        # We assume if we are given a number, but we are not given a letter
        # then this is using the implicit post release syntax (e.g. 1.0-1)
        letter = "post"

        return letter, int(number)

    return None 
开发者ID:tensorwerk,项目名称:hangar-py,代码行数:37,代码来源:_version.py

示例8: test_supports_int

# 需要导入模块: import typing [as 别名]
# 或者: from typing import SupportsInt [as 别名]
def test_supports_int(self):
        self.assertIsSubclass(int, typing.SupportsInt)
        self.assertNotIsSubclass(str, typing.SupportsInt) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:5,代码来源:test_typing.py

示例9: test_protocol_instance_type_error

# 需要导入模块: import typing [as 别名]
# 或者: from typing import SupportsInt [as 别名]
def test_protocol_instance_type_error(self):
        with self.assertRaises(TypeError):
            isinstance(0, typing.SupportsAbs)
        class C1(typing.SupportsInt):
            def __int__(self) -> int:
                return 42
        class C2(C1):
            pass
        c = C2()
        self.assertIsInstance(c, C1) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:12,代码来源:test_typing.py

示例10: DATE

# 需要导入模块: import typing [as 别名]
# 或者: from typing import SupportsInt [as 别名]
def DATE(
    ts: datetime, day_offset: SupportsInt = 0, hour_offset: SupportsInt = 0
) -> str:
    """Current day as a string"""
    day_offset, hour_offset = int(day_offset), int(hour_offset)
    offset_day = (ts + timedelta(days=day_offset, hours=hour_offset)).date()
    return str(offset_day) 
开发者ID:apache,项目名称:incubator-superset,代码行数:9,代码来源:superset_test_custom_template_processors.py


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