File: _compat.py

package info (click to toggle)
meson-python 0.17.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,120 kB
  • sloc: python: 2,788; ansic: 219; makefile: 8
file content (62 lines) | stat: -rw-r--r-- 1,442 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# SPDX-FileCopyrightText: 2021 Filipe LaĆ­ns <lains@riseup.net>
# SPDX-FileCopyrightText: 2021 Quansight, LLC
# SPDX-FileCopyrightText: 2022 The meson-python developers
#
# SPDX-License-Identifier: MIT

from __future__ import annotations

import functools
import importlib.resources
import os
import sys
import typing


if sys.version_info >= (3, 9):
    from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence
else:
    from typing import Collection, Iterable, Iterator, Mapping, Sequence


if sys.version_info >= (3, 8):
    from functools import cached_property
else:
    cached_property = lambda x: property(functools.lru_cache(maxsize=None)(x))  # noqa: E731


if sys.version_info >= (3, 9):
    def read_binary(package: str, resource: str) -> bytes:
        return importlib.resources.files(package).joinpath(resource).read_bytes()
else:
    read_binary = importlib.resources.read_binary


if typing.TYPE_CHECKING:
    from typing import Union

    if sys.version_info >= (3, 10):
        from typing import ParamSpec
    else:
        from typing_extensions import ParamSpec

    if sys.version_info >= (3, 11):
        from typing import Self
    else:
        from typing_extensions import Self

    Path = Union[str, os.PathLike]


__all__ = [
    'cached_property',
    'read_binary',
    'Collection',
    'Iterable',
    'Iterator',
    'Mapping',
    'Path',
    'ParamSpec',
    'Self',
    'Sequence',
]