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