Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- llmeval-env/lib/python3.10/site-packages/attr/__init__.py +134 -0
- llmeval-env/lib/python3.10/site-packages/attr/__init__.pyi +555 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_cmp.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_compat.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_config.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_funcs.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_make.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_next_gen.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_version_info.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/converters.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/exceptions.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/filters.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/setters.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/__pycache__/validators.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/_cmp.py +150 -0
- llmeval-env/lib/python3.10/site-packages/attr/_cmp.pyi +13 -0
- llmeval-env/lib/python3.10/site-packages/attr/_compat.py +87 -0
- llmeval-env/lib/python3.10/site-packages/attr/_config.py +31 -0
- llmeval-env/lib/python3.10/site-packages/attr/_funcs.py +483 -0
- llmeval-env/lib/python3.10/site-packages/attr/_make.py +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/_next_gen.py +229 -0
- llmeval-env/lib/python3.10/site-packages/attr/_typing_compat.pyi +15 -0
- llmeval-env/lib/python3.10/site-packages/attr/_version_info.py +86 -0
- llmeval-env/lib/python3.10/site-packages/attr/_version_info.pyi +9 -0
- llmeval-env/lib/python3.10/site-packages/attr/converters.py +144 -0
- llmeval-env/lib/python3.10/site-packages/attr/converters.pyi +13 -0
- llmeval-env/lib/python3.10/site-packages/attr/exceptions.py +95 -0
- llmeval-env/lib/python3.10/site-packages/attr/exceptions.pyi +17 -0
- llmeval-env/lib/python3.10/site-packages/attr/filters.py +66 -0
- llmeval-env/lib/python3.10/site-packages/attr/filters.pyi +6 -0
- llmeval-env/lib/python3.10/site-packages/attr/py.typed +0 -0
- llmeval-env/lib/python3.10/site-packages/attr/setters.py +73 -0
- llmeval-env/lib/python3.10/site-packages/attr/setters.pyi +19 -0
- llmeval-env/lib/python3.10/site-packages/attr/validators.py +681 -0
- llmeval-env/lib/python3.10/site-packages/attr/validators.pyi +88 -0
- llmeval-env/lib/python3.10/site-packages/joblib-1.4.2.dist-info/INSTALLER +1 -0
- llmeval-env/lib/python3.10/site-packages/joblib-1.4.2.dist-info/LICENSE.txt +29 -0
- llmeval-env/lib/python3.10/site-packages/joblib-1.4.2.dist-info/METADATA +165 -0
- llmeval-env/lib/python3.10/site-packages/more_itertools/__init__.py +6 -0
- llmeval-env/lib/python3.10/site-packages/more_itertools/__init__.pyi +2 -0
- llmeval-env/lib/python3.10/site-packages/more_itertools/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/more_itertools/__pycache__/more.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/more_itertools/__pycache__/recipes.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/more_itertools/more.py +0 -0
- llmeval-env/lib/python3.10/site-packages/more_itertools/more.pyi +695 -0
- llmeval-env/lib/python3.10/site-packages/more_itertools/py.typed +0 -0
- llmeval-env/lib/python3.10/site-packages/more_itertools/recipes.py +1012 -0
- llmeval-env/lib/python3.10/site-packages/more_itertools/recipes.pyi +128 -0
.gitattributes
CHANGED
@@ -101,3 +101,4 @@ llmeval-env/lib/python3.10/site-packages/nvidia/cuda_nvrtc/lib/libnvrtc-builtins
|
|
101 |
llmeval-env/lib/python3.10/site-packages/nvidia/cusolver/lib/libcusolverMg.so.11 filter=lfs diff=lfs merge=lfs -text
|
102 |
llmeval-env/lib/python3.10/site-packages/nvidia/cuda_nvrtc/lib/libnvrtc.so.12 filter=lfs diff=lfs merge=lfs -text
|
103 |
llmeval-env/lib/python3.10/site-packages/nvidia/cufft/lib/libcufftw.so.11 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
101 |
llmeval-env/lib/python3.10/site-packages/nvidia/cusolver/lib/libcusolverMg.so.11 filter=lfs diff=lfs merge=lfs -text
|
102 |
llmeval-env/lib/python3.10/site-packages/nvidia/cuda_nvrtc/lib/libnvrtc.so.12 filter=lfs diff=lfs merge=lfs -text
|
103 |
llmeval-env/lib/python3.10/site-packages/nvidia/cufft/lib/libcufftw.so.11 filter=lfs diff=lfs merge=lfs -text
|
104 |
+
llmeval-env/lib/python3.10/site-packages/nvidia/cusolver/lib/libcusolver.so.11 filter=lfs diff=lfs merge=lfs -text
|
llmeval-env/lib/python3.10/site-packages/attr/__init__.py
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
"""
|
4 |
+
Classes Without Boilerplate
|
5 |
+
"""
|
6 |
+
|
7 |
+
from functools import partial
|
8 |
+
from typing import Callable
|
9 |
+
|
10 |
+
from . import converters, exceptions, filters, setters, validators
|
11 |
+
from ._cmp import cmp_using
|
12 |
+
from ._compat import Protocol
|
13 |
+
from ._config import get_run_validators, set_run_validators
|
14 |
+
from ._funcs import asdict, assoc, astuple, evolve, has, resolve_types
|
15 |
+
from ._make import (
|
16 |
+
NOTHING,
|
17 |
+
Attribute,
|
18 |
+
Factory,
|
19 |
+
attrib,
|
20 |
+
attrs,
|
21 |
+
fields,
|
22 |
+
fields_dict,
|
23 |
+
make_class,
|
24 |
+
validate,
|
25 |
+
)
|
26 |
+
from ._next_gen import define, field, frozen, mutable
|
27 |
+
from ._version_info import VersionInfo
|
28 |
+
|
29 |
+
|
30 |
+
s = attributes = attrs
|
31 |
+
ib = attr = attrib
|
32 |
+
dataclass = partial(attrs, auto_attribs=True) # happy Easter ;)
|
33 |
+
|
34 |
+
|
35 |
+
class AttrsInstance(Protocol):
|
36 |
+
pass
|
37 |
+
|
38 |
+
|
39 |
+
__all__ = [
|
40 |
+
"Attribute",
|
41 |
+
"AttrsInstance",
|
42 |
+
"Factory",
|
43 |
+
"NOTHING",
|
44 |
+
"asdict",
|
45 |
+
"assoc",
|
46 |
+
"astuple",
|
47 |
+
"attr",
|
48 |
+
"attrib",
|
49 |
+
"attributes",
|
50 |
+
"attrs",
|
51 |
+
"cmp_using",
|
52 |
+
"converters",
|
53 |
+
"define",
|
54 |
+
"evolve",
|
55 |
+
"exceptions",
|
56 |
+
"field",
|
57 |
+
"fields",
|
58 |
+
"fields_dict",
|
59 |
+
"filters",
|
60 |
+
"frozen",
|
61 |
+
"get_run_validators",
|
62 |
+
"has",
|
63 |
+
"ib",
|
64 |
+
"make_class",
|
65 |
+
"mutable",
|
66 |
+
"resolve_types",
|
67 |
+
"s",
|
68 |
+
"set_run_validators",
|
69 |
+
"setters",
|
70 |
+
"validate",
|
71 |
+
"validators",
|
72 |
+
]
|
73 |
+
|
74 |
+
|
75 |
+
def _make_getattr(mod_name: str) -> Callable:
|
76 |
+
"""
|
77 |
+
Create a metadata proxy for packaging information that uses *mod_name* in
|
78 |
+
its warnings and errors.
|
79 |
+
"""
|
80 |
+
|
81 |
+
def __getattr__(name: str) -> str:
|
82 |
+
dunder_to_metadata = {
|
83 |
+
"__title__": "Name",
|
84 |
+
"__copyright__": "",
|
85 |
+
"__version__": "version",
|
86 |
+
"__version_info__": "version",
|
87 |
+
"__description__": "summary",
|
88 |
+
"__uri__": "",
|
89 |
+
"__url__": "",
|
90 |
+
"__author__": "",
|
91 |
+
"__email__": "",
|
92 |
+
"__license__": "license",
|
93 |
+
}
|
94 |
+
if name not in dunder_to_metadata:
|
95 |
+
msg = f"module {mod_name} has no attribute {name}"
|
96 |
+
raise AttributeError(msg)
|
97 |
+
|
98 |
+
import sys
|
99 |
+
import warnings
|
100 |
+
|
101 |
+
if sys.version_info < (3, 8):
|
102 |
+
from importlib_metadata import metadata
|
103 |
+
else:
|
104 |
+
from importlib.metadata import metadata
|
105 |
+
|
106 |
+
if name not in ("__version__", "__version_info__"):
|
107 |
+
warnings.warn(
|
108 |
+
f"Accessing {mod_name}.{name} is deprecated and will be "
|
109 |
+
"removed in a future release. Use importlib.metadata directly "
|
110 |
+
"to query for attrs's packaging metadata.",
|
111 |
+
DeprecationWarning,
|
112 |
+
stacklevel=2,
|
113 |
+
)
|
114 |
+
|
115 |
+
meta = metadata("attrs")
|
116 |
+
if name == "__license__":
|
117 |
+
return "MIT"
|
118 |
+
if name == "__copyright__":
|
119 |
+
return "Copyright (c) 2015 Hynek Schlawack"
|
120 |
+
if name in ("__uri__", "__url__"):
|
121 |
+
return meta["Project-URL"].split(" ", 1)[-1]
|
122 |
+
if name == "__version_info__":
|
123 |
+
return VersionInfo._from_version_string(meta["version"])
|
124 |
+
if name == "__author__":
|
125 |
+
return meta["Author-email"].rsplit(" ", 1)[0]
|
126 |
+
if name == "__email__":
|
127 |
+
return meta["Author-email"].rsplit("<", 1)[1][:-1]
|
128 |
+
|
129 |
+
return meta[dunder_to_metadata[name]]
|
130 |
+
|
131 |
+
return __getattr__
|
132 |
+
|
133 |
+
|
134 |
+
__getattr__ = _make_getattr(__name__)
|
llmeval-env/lib/python3.10/site-packages/attr/__init__.pyi
ADDED
@@ -0,0 +1,555 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import enum
|
2 |
+
import sys
|
3 |
+
|
4 |
+
from typing import (
|
5 |
+
Any,
|
6 |
+
Callable,
|
7 |
+
Dict,
|
8 |
+
Generic,
|
9 |
+
List,
|
10 |
+
Mapping,
|
11 |
+
Optional,
|
12 |
+
Protocol,
|
13 |
+
Sequence,
|
14 |
+
Tuple,
|
15 |
+
Type,
|
16 |
+
TypeVar,
|
17 |
+
Union,
|
18 |
+
overload,
|
19 |
+
)
|
20 |
+
|
21 |
+
# `import X as X` is required to make these public
|
22 |
+
from . import converters as converters
|
23 |
+
from . import exceptions as exceptions
|
24 |
+
from . import filters as filters
|
25 |
+
from . import setters as setters
|
26 |
+
from . import validators as validators
|
27 |
+
from ._cmp import cmp_using as cmp_using
|
28 |
+
from ._typing_compat import AttrsInstance_
|
29 |
+
from ._version_info import VersionInfo
|
30 |
+
|
31 |
+
if sys.version_info >= (3, 10):
|
32 |
+
from typing import TypeGuard
|
33 |
+
else:
|
34 |
+
from typing_extensions import TypeGuard
|
35 |
+
|
36 |
+
if sys.version_info >= (3, 11):
|
37 |
+
from typing import dataclass_transform
|
38 |
+
else:
|
39 |
+
from typing_extensions import dataclass_transform
|
40 |
+
|
41 |
+
__version__: str
|
42 |
+
__version_info__: VersionInfo
|
43 |
+
__title__: str
|
44 |
+
__description__: str
|
45 |
+
__url__: str
|
46 |
+
__uri__: str
|
47 |
+
__author__: str
|
48 |
+
__email__: str
|
49 |
+
__license__: str
|
50 |
+
__copyright__: str
|
51 |
+
|
52 |
+
_T = TypeVar("_T")
|
53 |
+
_C = TypeVar("_C", bound=type)
|
54 |
+
|
55 |
+
_EqOrderType = Union[bool, Callable[[Any], Any]]
|
56 |
+
_ValidatorType = Callable[[Any, "Attribute[_T]", _T], Any]
|
57 |
+
_ConverterType = Callable[[Any], Any]
|
58 |
+
_FilterType = Callable[["Attribute[_T]", _T], bool]
|
59 |
+
_ReprType = Callable[[Any], str]
|
60 |
+
_ReprArgType = Union[bool, _ReprType]
|
61 |
+
_OnSetAttrType = Callable[[Any, "Attribute[Any]", Any], Any]
|
62 |
+
_OnSetAttrArgType = Union[
|
63 |
+
_OnSetAttrType, List[_OnSetAttrType], setters._NoOpType
|
64 |
+
]
|
65 |
+
_FieldTransformer = Callable[
|
66 |
+
[type, List["Attribute[Any]"]], List["Attribute[Any]"]
|
67 |
+
]
|
68 |
+
# FIXME: in reality, if multiple validators are passed they must be in a list
|
69 |
+
# or tuple, but those are invariant and so would prevent subtypes of
|
70 |
+
# _ValidatorType from working when passed in a list or tuple.
|
71 |
+
_ValidatorArgType = Union[_ValidatorType[_T], Sequence[_ValidatorType[_T]]]
|
72 |
+
|
73 |
+
# We subclass this here to keep the protocol's qualified name clean.
|
74 |
+
class AttrsInstance(AttrsInstance_, Protocol):
|
75 |
+
pass
|
76 |
+
|
77 |
+
_A = TypeVar("_A", bound=type[AttrsInstance])
|
78 |
+
|
79 |
+
class _Nothing(enum.Enum):
|
80 |
+
NOTHING = enum.auto()
|
81 |
+
|
82 |
+
NOTHING = _Nothing.NOTHING
|
83 |
+
|
84 |
+
# NOTE: Factory lies about its return type to make this possible:
|
85 |
+
# `x: List[int] # = Factory(list)`
|
86 |
+
# Work around mypy issue #4554 in the common case by using an overload.
|
87 |
+
if sys.version_info >= (3, 8):
|
88 |
+
from typing import Literal
|
89 |
+
@overload
|
90 |
+
def Factory(factory: Callable[[], _T]) -> _T: ...
|
91 |
+
@overload
|
92 |
+
def Factory(
|
93 |
+
factory: Callable[[Any], _T],
|
94 |
+
takes_self: Literal[True],
|
95 |
+
) -> _T: ...
|
96 |
+
@overload
|
97 |
+
def Factory(
|
98 |
+
factory: Callable[[], _T],
|
99 |
+
takes_self: Literal[False],
|
100 |
+
) -> _T: ...
|
101 |
+
|
102 |
+
else:
|
103 |
+
@overload
|
104 |
+
def Factory(factory: Callable[[], _T]) -> _T: ...
|
105 |
+
@overload
|
106 |
+
def Factory(
|
107 |
+
factory: Union[Callable[[Any], _T], Callable[[], _T]],
|
108 |
+
takes_self: bool = ...,
|
109 |
+
) -> _T: ...
|
110 |
+
|
111 |
+
class Attribute(Generic[_T]):
|
112 |
+
name: str
|
113 |
+
default: Optional[_T]
|
114 |
+
validator: Optional[_ValidatorType[_T]]
|
115 |
+
repr: _ReprArgType
|
116 |
+
cmp: _EqOrderType
|
117 |
+
eq: _EqOrderType
|
118 |
+
order: _EqOrderType
|
119 |
+
hash: Optional[bool]
|
120 |
+
init: bool
|
121 |
+
converter: Optional[_ConverterType]
|
122 |
+
metadata: Dict[Any, Any]
|
123 |
+
type: Optional[Type[_T]]
|
124 |
+
kw_only: bool
|
125 |
+
on_setattr: _OnSetAttrType
|
126 |
+
alias: Optional[str]
|
127 |
+
|
128 |
+
def evolve(self, **changes: Any) -> "Attribute[Any]": ...
|
129 |
+
|
130 |
+
# NOTE: We had several choices for the annotation to use for type arg:
|
131 |
+
# 1) Type[_T]
|
132 |
+
# - Pros: Handles simple cases correctly
|
133 |
+
# - Cons: Might produce less informative errors in the case of conflicting
|
134 |
+
# TypeVars e.g. `attr.ib(default='bad', type=int)`
|
135 |
+
# 2) Callable[..., _T]
|
136 |
+
# - Pros: Better error messages than #1 for conflicting TypeVars
|
137 |
+
# - Cons: Terrible error messages for validator checks.
|
138 |
+
# e.g. attr.ib(type=int, validator=validate_str)
|
139 |
+
# -> error: Cannot infer function type argument
|
140 |
+
# 3) type (and do all of the work in the mypy plugin)
|
141 |
+
# - Pros: Simple here, and we could customize the plugin with our own errors.
|
142 |
+
# - Cons: Would need to write mypy plugin code to handle all the cases.
|
143 |
+
# We chose option #1.
|
144 |
+
|
145 |
+
# `attr` lies about its return type to make the following possible:
|
146 |
+
# attr() -> Any
|
147 |
+
# attr(8) -> int
|
148 |
+
# attr(validator=<some callable>) -> Whatever the callable expects.
|
149 |
+
# This makes this type of assignments possible:
|
150 |
+
# x: int = attr(8)
|
151 |
+
#
|
152 |
+
# This form catches explicit None or no default but with no other arguments
|
153 |
+
# returns Any.
|
154 |
+
@overload
|
155 |
+
def attrib(
|
156 |
+
default: None = ...,
|
157 |
+
validator: None = ...,
|
158 |
+
repr: _ReprArgType = ...,
|
159 |
+
cmp: Optional[_EqOrderType] = ...,
|
160 |
+
hash: Optional[bool] = ...,
|
161 |
+
init: bool = ...,
|
162 |
+
metadata: Optional[Mapping[Any, Any]] = ...,
|
163 |
+
type: None = ...,
|
164 |
+
converter: None = ...,
|
165 |
+
factory: None = ...,
|
166 |
+
kw_only: bool = ...,
|
167 |
+
eq: Optional[_EqOrderType] = ...,
|
168 |
+
order: Optional[_EqOrderType] = ...,
|
169 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
170 |
+
alias: Optional[str] = ...,
|
171 |
+
) -> Any: ...
|
172 |
+
|
173 |
+
# This form catches an explicit None or no default and infers the type from the
|
174 |
+
# other arguments.
|
175 |
+
@overload
|
176 |
+
def attrib(
|
177 |
+
default: None = ...,
|
178 |
+
validator: Optional[_ValidatorArgType[_T]] = ...,
|
179 |
+
repr: _ReprArgType = ...,
|
180 |
+
cmp: Optional[_EqOrderType] = ...,
|
181 |
+
hash: Optional[bool] = ...,
|
182 |
+
init: bool = ...,
|
183 |
+
metadata: Optional[Mapping[Any, Any]] = ...,
|
184 |
+
type: Optional[Type[_T]] = ...,
|
185 |
+
converter: Optional[_ConverterType] = ...,
|
186 |
+
factory: Optional[Callable[[], _T]] = ...,
|
187 |
+
kw_only: bool = ...,
|
188 |
+
eq: Optional[_EqOrderType] = ...,
|
189 |
+
order: Optional[_EqOrderType] = ...,
|
190 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
191 |
+
alias: Optional[str] = ...,
|
192 |
+
) -> _T: ...
|
193 |
+
|
194 |
+
# This form catches an explicit default argument.
|
195 |
+
@overload
|
196 |
+
def attrib(
|
197 |
+
default: _T,
|
198 |
+
validator: Optional[_ValidatorArgType[_T]] = ...,
|
199 |
+
repr: _ReprArgType = ...,
|
200 |
+
cmp: Optional[_EqOrderType] = ...,
|
201 |
+
hash: Optional[bool] = ...,
|
202 |
+
init: bool = ...,
|
203 |
+
metadata: Optional[Mapping[Any, Any]] = ...,
|
204 |
+
type: Optional[Type[_T]] = ...,
|
205 |
+
converter: Optional[_ConverterType] = ...,
|
206 |
+
factory: Optional[Callable[[], _T]] = ...,
|
207 |
+
kw_only: bool = ...,
|
208 |
+
eq: Optional[_EqOrderType] = ...,
|
209 |
+
order: Optional[_EqOrderType] = ...,
|
210 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
211 |
+
alias: Optional[str] = ...,
|
212 |
+
) -> _T: ...
|
213 |
+
|
214 |
+
# This form covers type=non-Type: e.g. forward references (str), Any
|
215 |
+
@overload
|
216 |
+
def attrib(
|
217 |
+
default: Optional[_T] = ...,
|
218 |
+
validator: Optional[_ValidatorArgType[_T]] = ...,
|
219 |
+
repr: _ReprArgType = ...,
|
220 |
+
cmp: Optional[_EqOrderType] = ...,
|
221 |
+
hash: Optional[bool] = ...,
|
222 |
+
init: bool = ...,
|
223 |
+
metadata: Optional[Mapping[Any, Any]] = ...,
|
224 |
+
type: object = ...,
|
225 |
+
converter: Optional[_ConverterType] = ...,
|
226 |
+
factory: Optional[Callable[[], _T]] = ...,
|
227 |
+
kw_only: bool = ...,
|
228 |
+
eq: Optional[_EqOrderType] = ...,
|
229 |
+
order: Optional[_EqOrderType] = ...,
|
230 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
231 |
+
alias: Optional[str] = ...,
|
232 |
+
) -> Any: ...
|
233 |
+
@overload
|
234 |
+
def field(
|
235 |
+
*,
|
236 |
+
default: None = ...,
|
237 |
+
validator: None = ...,
|
238 |
+
repr: _ReprArgType = ...,
|
239 |
+
hash: Optional[bool] = ...,
|
240 |
+
init: bool = ...,
|
241 |
+
metadata: Optional[Mapping[Any, Any]] = ...,
|
242 |
+
converter: None = ...,
|
243 |
+
factory: None = ...,
|
244 |
+
kw_only: bool = ...,
|
245 |
+
eq: Optional[bool] = ...,
|
246 |
+
order: Optional[bool] = ...,
|
247 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
248 |
+
alias: Optional[str] = ...,
|
249 |
+
type: Optional[type] = ...,
|
250 |
+
) -> Any: ...
|
251 |
+
|
252 |
+
# This form catches an explicit None or no default and infers the type from the
|
253 |
+
# other arguments.
|
254 |
+
@overload
|
255 |
+
def field(
|
256 |
+
*,
|
257 |
+
default: None = ...,
|
258 |
+
validator: Optional[_ValidatorArgType[_T]] = ...,
|
259 |
+
repr: _ReprArgType = ...,
|
260 |
+
hash: Optional[bool] = ...,
|
261 |
+
init: bool = ...,
|
262 |
+
metadata: Optional[Mapping[Any, Any]] = ...,
|
263 |
+
converter: Optional[_ConverterType] = ...,
|
264 |
+
factory: Optional[Callable[[], _T]] = ...,
|
265 |
+
kw_only: bool = ...,
|
266 |
+
eq: Optional[_EqOrderType] = ...,
|
267 |
+
order: Optional[_EqOrderType] = ...,
|
268 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
269 |
+
alias: Optional[str] = ...,
|
270 |
+
type: Optional[type] = ...,
|
271 |
+
) -> _T: ...
|
272 |
+
|
273 |
+
# This form catches an explicit default argument.
|
274 |
+
@overload
|
275 |
+
def field(
|
276 |
+
*,
|
277 |
+
default: _T,
|
278 |
+
validator: Optional[_ValidatorArgType[_T]] = ...,
|
279 |
+
repr: _ReprArgType = ...,
|
280 |
+
hash: Optional[bool] = ...,
|
281 |
+
init: bool = ...,
|
282 |
+
metadata: Optional[Mapping[Any, Any]] = ...,
|
283 |
+
converter: Optional[_ConverterType] = ...,
|
284 |
+
factory: Optional[Callable[[], _T]] = ...,
|
285 |
+
kw_only: bool = ...,
|
286 |
+
eq: Optional[_EqOrderType] = ...,
|
287 |
+
order: Optional[_EqOrderType] = ...,
|
288 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
289 |
+
alias: Optional[str] = ...,
|
290 |
+
type: Optional[type] = ...,
|
291 |
+
) -> _T: ...
|
292 |
+
|
293 |
+
# This form covers type=non-Type: e.g. forward references (str), Any
|
294 |
+
@overload
|
295 |
+
def field(
|
296 |
+
*,
|
297 |
+
default: Optional[_T] = ...,
|
298 |
+
validator: Optional[_ValidatorArgType[_T]] = ...,
|
299 |
+
repr: _ReprArgType = ...,
|
300 |
+
hash: Optional[bool] = ...,
|
301 |
+
init: bool = ...,
|
302 |
+
metadata: Optional[Mapping[Any, Any]] = ...,
|
303 |
+
converter: Optional[_ConverterType] = ...,
|
304 |
+
factory: Optional[Callable[[], _T]] = ...,
|
305 |
+
kw_only: bool = ...,
|
306 |
+
eq: Optional[_EqOrderType] = ...,
|
307 |
+
order: Optional[_EqOrderType] = ...,
|
308 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
309 |
+
alias: Optional[str] = ...,
|
310 |
+
type: Optional[type] = ...,
|
311 |
+
) -> Any: ...
|
312 |
+
@overload
|
313 |
+
@dataclass_transform(order_default=True, field_specifiers=(attrib, field))
|
314 |
+
def attrs(
|
315 |
+
maybe_cls: _C,
|
316 |
+
these: Optional[Dict[str, Any]] = ...,
|
317 |
+
repr_ns: Optional[str] = ...,
|
318 |
+
repr: bool = ...,
|
319 |
+
cmp: Optional[_EqOrderType] = ...,
|
320 |
+
hash: Optional[bool] = ...,
|
321 |
+
init: bool = ...,
|
322 |
+
slots: bool = ...,
|
323 |
+
frozen: bool = ...,
|
324 |
+
weakref_slot: bool = ...,
|
325 |
+
str: bool = ...,
|
326 |
+
auto_attribs: bool = ...,
|
327 |
+
kw_only: bool = ...,
|
328 |
+
cache_hash: bool = ...,
|
329 |
+
auto_exc: bool = ...,
|
330 |
+
eq: Optional[_EqOrderType] = ...,
|
331 |
+
order: Optional[_EqOrderType] = ...,
|
332 |
+
auto_detect: bool = ...,
|
333 |
+
collect_by_mro: bool = ...,
|
334 |
+
getstate_setstate: Optional[bool] = ...,
|
335 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
336 |
+
field_transformer: Optional[_FieldTransformer] = ...,
|
337 |
+
match_args: bool = ...,
|
338 |
+
unsafe_hash: Optional[bool] = ...,
|
339 |
+
) -> _C: ...
|
340 |
+
@overload
|
341 |
+
@dataclass_transform(order_default=True, field_specifiers=(attrib, field))
|
342 |
+
def attrs(
|
343 |
+
maybe_cls: None = ...,
|
344 |
+
these: Optional[Dict[str, Any]] = ...,
|
345 |
+
repr_ns: Optional[str] = ...,
|
346 |
+
repr: bool = ...,
|
347 |
+
cmp: Optional[_EqOrderType] = ...,
|
348 |
+
hash: Optional[bool] = ...,
|
349 |
+
init: bool = ...,
|
350 |
+
slots: bool = ...,
|
351 |
+
frozen: bool = ...,
|
352 |
+
weakref_slot: bool = ...,
|
353 |
+
str: bool = ...,
|
354 |
+
auto_attribs: bool = ...,
|
355 |
+
kw_only: bool = ...,
|
356 |
+
cache_hash: bool = ...,
|
357 |
+
auto_exc: bool = ...,
|
358 |
+
eq: Optional[_EqOrderType] = ...,
|
359 |
+
order: Optional[_EqOrderType] = ...,
|
360 |
+
auto_detect: bool = ...,
|
361 |
+
collect_by_mro: bool = ...,
|
362 |
+
getstate_setstate: Optional[bool] = ...,
|
363 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
364 |
+
field_transformer: Optional[_FieldTransformer] = ...,
|
365 |
+
match_args: bool = ...,
|
366 |
+
unsafe_hash: Optional[bool] = ...,
|
367 |
+
) -> Callable[[_C], _C]: ...
|
368 |
+
@overload
|
369 |
+
@dataclass_transform(field_specifiers=(attrib, field))
|
370 |
+
def define(
|
371 |
+
maybe_cls: _C,
|
372 |
+
*,
|
373 |
+
these: Optional[Dict[str, Any]] = ...,
|
374 |
+
repr: bool = ...,
|
375 |
+
unsafe_hash: Optional[bool] = ...,
|
376 |
+
hash: Optional[bool] = ...,
|
377 |
+
init: bool = ...,
|
378 |
+
slots: bool = ...,
|
379 |
+
frozen: bool = ...,
|
380 |
+
weakref_slot: bool = ...,
|
381 |
+
str: bool = ...,
|
382 |
+
auto_attribs: bool = ...,
|
383 |
+
kw_only: bool = ...,
|
384 |
+
cache_hash: bool = ...,
|
385 |
+
auto_exc: bool = ...,
|
386 |
+
eq: Optional[bool] = ...,
|
387 |
+
order: Optional[bool] = ...,
|
388 |
+
auto_detect: bool = ...,
|
389 |
+
getstate_setstate: Optional[bool] = ...,
|
390 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
391 |
+
field_transformer: Optional[_FieldTransformer] = ...,
|
392 |
+
match_args: bool = ...,
|
393 |
+
) -> _C: ...
|
394 |
+
@overload
|
395 |
+
@dataclass_transform(field_specifiers=(attrib, field))
|
396 |
+
def define(
|
397 |
+
maybe_cls: None = ...,
|
398 |
+
*,
|
399 |
+
these: Optional[Dict[str, Any]] = ...,
|
400 |
+
repr: bool = ...,
|
401 |
+
unsafe_hash: Optional[bool] = ...,
|
402 |
+
hash: Optional[bool] = ...,
|
403 |
+
init: bool = ...,
|
404 |
+
slots: bool = ...,
|
405 |
+
frozen: bool = ...,
|
406 |
+
weakref_slot: bool = ...,
|
407 |
+
str: bool = ...,
|
408 |
+
auto_attribs: bool = ...,
|
409 |
+
kw_only: bool = ...,
|
410 |
+
cache_hash: bool = ...,
|
411 |
+
auto_exc: bool = ...,
|
412 |
+
eq: Optional[bool] = ...,
|
413 |
+
order: Optional[bool] = ...,
|
414 |
+
auto_detect: bool = ...,
|
415 |
+
getstate_setstate: Optional[bool] = ...,
|
416 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
417 |
+
field_transformer: Optional[_FieldTransformer] = ...,
|
418 |
+
match_args: bool = ...,
|
419 |
+
) -> Callable[[_C], _C]: ...
|
420 |
+
|
421 |
+
mutable = define
|
422 |
+
|
423 |
+
@overload
|
424 |
+
@dataclass_transform(frozen_default=True, field_specifiers=(attrib, field))
|
425 |
+
def frozen(
|
426 |
+
maybe_cls: _C,
|
427 |
+
*,
|
428 |
+
these: Optional[Dict[str, Any]] = ...,
|
429 |
+
repr: bool = ...,
|
430 |
+
unsafe_hash: Optional[bool] = ...,
|
431 |
+
hash: Optional[bool] = ...,
|
432 |
+
init: bool = ...,
|
433 |
+
slots: bool = ...,
|
434 |
+
frozen: bool = ...,
|
435 |
+
weakref_slot: bool = ...,
|
436 |
+
str: bool = ...,
|
437 |
+
auto_attribs: bool = ...,
|
438 |
+
kw_only: bool = ...,
|
439 |
+
cache_hash: bool = ...,
|
440 |
+
auto_exc: bool = ...,
|
441 |
+
eq: Optional[bool] = ...,
|
442 |
+
order: Optional[bool] = ...,
|
443 |
+
auto_detect: bool = ...,
|
444 |
+
getstate_setstate: Optional[bool] = ...,
|
445 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
446 |
+
field_transformer: Optional[_FieldTransformer] = ...,
|
447 |
+
match_args: bool = ...,
|
448 |
+
) -> _C: ...
|
449 |
+
@overload
|
450 |
+
@dataclass_transform(frozen_default=True, field_specifiers=(attrib, field))
|
451 |
+
def frozen(
|
452 |
+
maybe_cls: None = ...,
|
453 |
+
*,
|
454 |
+
these: Optional[Dict[str, Any]] = ...,
|
455 |
+
repr: bool = ...,
|
456 |
+
unsafe_hash: Optional[bool] = ...,
|
457 |
+
hash: Optional[bool] = ...,
|
458 |
+
init: bool = ...,
|
459 |
+
slots: bool = ...,
|
460 |
+
frozen: bool = ...,
|
461 |
+
weakref_slot: bool = ...,
|
462 |
+
str: bool = ...,
|
463 |
+
auto_attribs: bool = ...,
|
464 |
+
kw_only: bool = ...,
|
465 |
+
cache_hash: bool = ...,
|
466 |
+
auto_exc: bool = ...,
|
467 |
+
eq: Optional[bool] = ...,
|
468 |
+
order: Optional[bool] = ...,
|
469 |
+
auto_detect: bool = ...,
|
470 |
+
getstate_setstate: Optional[bool] = ...,
|
471 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
472 |
+
field_transformer: Optional[_FieldTransformer] = ...,
|
473 |
+
match_args: bool = ...,
|
474 |
+
) -> Callable[[_C], _C]: ...
|
475 |
+
def fields(cls: Type[AttrsInstance]) -> Any: ...
|
476 |
+
def fields_dict(cls: Type[AttrsInstance]) -> Dict[str, Attribute[Any]]: ...
|
477 |
+
def validate(inst: AttrsInstance) -> None: ...
|
478 |
+
def resolve_types(
|
479 |
+
cls: _A,
|
480 |
+
globalns: Optional[Dict[str, Any]] = ...,
|
481 |
+
localns: Optional[Dict[str, Any]] = ...,
|
482 |
+
attribs: Optional[List[Attribute[Any]]] = ...,
|
483 |
+
include_extras: bool = ...,
|
484 |
+
) -> _A: ...
|
485 |
+
|
486 |
+
# TODO: add support for returning a proper attrs class from the mypy plugin
|
487 |
+
# we use Any instead of _CountingAttr so that e.g. `make_class('Foo',
|
488 |
+
# [attr.ib()])` is valid
|
489 |
+
def make_class(
|
490 |
+
name: str,
|
491 |
+
attrs: Union[List[str], Tuple[str, ...], Dict[str, Any]],
|
492 |
+
bases: Tuple[type, ...] = ...,
|
493 |
+
class_body: Optional[Dict[str, Any]] = ...,
|
494 |
+
repr_ns: Optional[str] = ...,
|
495 |
+
repr: bool = ...,
|
496 |
+
cmp: Optional[_EqOrderType] = ...,
|
497 |
+
hash: Optional[bool] = ...,
|
498 |
+
init: bool = ...,
|
499 |
+
slots: bool = ...,
|
500 |
+
frozen: bool = ...,
|
501 |
+
weakref_slot: bool = ...,
|
502 |
+
str: bool = ...,
|
503 |
+
auto_attribs: bool = ...,
|
504 |
+
kw_only: bool = ...,
|
505 |
+
cache_hash: bool = ...,
|
506 |
+
auto_exc: bool = ...,
|
507 |
+
eq: Optional[_EqOrderType] = ...,
|
508 |
+
order: Optional[_EqOrderType] = ...,
|
509 |
+
collect_by_mro: bool = ...,
|
510 |
+
on_setattr: Optional[_OnSetAttrArgType] = ...,
|
511 |
+
field_transformer: Optional[_FieldTransformer] = ...,
|
512 |
+
) -> type: ...
|
513 |
+
|
514 |
+
# _funcs --
|
515 |
+
|
516 |
+
# TODO: add support for returning TypedDict from the mypy plugin
|
517 |
+
# FIXME: asdict/astuple do not honor their factory args. Waiting on one of
|
518 |
+
# these:
|
519 |
+
# https://github.com/python/mypy/issues/4236
|
520 |
+
# https://github.com/python/typing/issues/253
|
521 |
+
# XXX: remember to fix attrs.asdict/astuple too!
|
522 |
+
def asdict(
|
523 |
+
inst: AttrsInstance,
|
524 |
+
recurse: bool = ...,
|
525 |
+
filter: Optional[_FilterType[Any]] = ...,
|
526 |
+
dict_factory: Type[Mapping[Any, Any]] = ...,
|
527 |
+
retain_collection_types: bool = ...,
|
528 |
+
value_serializer: Optional[
|
529 |
+
Callable[[type, Attribute[Any], Any], Any]
|
530 |
+
] = ...,
|
531 |
+
tuple_keys: Optional[bool] = ...,
|
532 |
+
) -> Dict[str, Any]: ...
|
533 |
+
|
534 |
+
# TODO: add support for returning NamedTuple from the mypy plugin
|
535 |
+
def astuple(
|
536 |
+
inst: AttrsInstance,
|
537 |
+
recurse: bool = ...,
|
538 |
+
filter: Optional[_FilterType[Any]] = ...,
|
539 |
+
tuple_factory: Type[Sequence[Any]] = ...,
|
540 |
+
retain_collection_types: bool = ...,
|
541 |
+
) -> Tuple[Any, ...]: ...
|
542 |
+
def has(cls: type) -> TypeGuard[Type[AttrsInstance]]: ...
|
543 |
+
def assoc(inst: _T, **changes: Any) -> _T: ...
|
544 |
+
def evolve(inst: _T, **changes: Any) -> _T: ...
|
545 |
+
|
546 |
+
# _config --
|
547 |
+
|
548 |
+
def set_run_validators(run: bool) -> None: ...
|
549 |
+
def get_run_validators() -> bool: ...
|
550 |
+
|
551 |
+
# aliases --
|
552 |
+
|
553 |
+
s = attributes = attrs
|
554 |
+
ib = attr = attrib
|
555 |
+
dataclass = attrs # Technically, partial(attrs, auto_attribs=True) ;)
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (3.01 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_cmp.cpython-310.pyc
ADDED
Binary file (3.94 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_compat.cpython-310.pyc
ADDED
Binary file (2.21 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_config.cpython-310.pyc
ADDED
Binary file (1.01 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_funcs.cpython-310.pyc
ADDED
Binary file (11.8 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_make.cpython-310.pyc
ADDED
Binary file (75.3 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_next_gen.cpython-310.pyc
ADDED
Binary file (5.43 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/_version_info.cpython-310.pyc
ADDED
Binary file (2.32 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/converters.cpython-310.pyc
ADDED
Binary file (3.55 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/exceptions.cpython-310.pyc
ADDED
Binary file (3.17 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/filters.cpython-310.pyc
ADDED
Binary file (1.92 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/setters.cpython-310.pyc
ADDED
Binary file (1.52 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/__pycache__/validators.cpython-310.pyc
ADDED
Binary file (19.7 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/attr/_cmp.py
ADDED
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
|
4 |
+
import functools
|
5 |
+
import types
|
6 |
+
|
7 |
+
from ._make import _make_ne
|
8 |
+
|
9 |
+
|
10 |
+
_operation_names = {"eq": "==", "lt": "<", "le": "<=", "gt": ">", "ge": ">="}
|
11 |
+
|
12 |
+
|
13 |
+
def cmp_using(
|
14 |
+
eq=None,
|
15 |
+
lt=None,
|
16 |
+
le=None,
|
17 |
+
gt=None,
|
18 |
+
ge=None,
|
19 |
+
require_same_type=True,
|
20 |
+
class_name="Comparable",
|
21 |
+
):
|
22 |
+
"""
|
23 |
+
Create a class that can be passed into `attrs.field`'s ``eq``, ``order``,
|
24 |
+
and ``cmp`` arguments to customize field comparison.
|
25 |
+
|
26 |
+
The resulting class will have a full set of ordering methods if at least
|
27 |
+
one of ``{lt, le, gt, ge}`` and ``eq`` are provided.
|
28 |
+
|
29 |
+
:param Optional[callable] eq: `callable` used to evaluate equality of two
|
30 |
+
objects.
|
31 |
+
:param Optional[callable] lt: `callable` used to evaluate whether one
|
32 |
+
object is less than another object.
|
33 |
+
:param Optional[callable] le: `callable` used to evaluate whether one
|
34 |
+
object is less than or equal to another object.
|
35 |
+
:param Optional[callable] gt: `callable` used to evaluate whether one
|
36 |
+
object is greater than another object.
|
37 |
+
:param Optional[callable] ge: `callable` used to evaluate whether one
|
38 |
+
object is greater than or equal to another object.
|
39 |
+
|
40 |
+
:param bool require_same_type: When `True`, equality and ordering methods
|
41 |
+
will return `NotImplemented` if objects are not of the same type.
|
42 |
+
|
43 |
+
:param Optional[str] class_name: Name of class. Defaults to 'Comparable'.
|
44 |
+
|
45 |
+
See `comparison` for more details.
|
46 |
+
|
47 |
+
.. versionadded:: 21.1.0
|
48 |
+
"""
|
49 |
+
|
50 |
+
body = {
|
51 |
+
"__slots__": ["value"],
|
52 |
+
"__init__": _make_init(),
|
53 |
+
"_requirements": [],
|
54 |
+
"_is_comparable_to": _is_comparable_to,
|
55 |
+
}
|
56 |
+
|
57 |
+
# Add operations.
|
58 |
+
num_order_functions = 0
|
59 |
+
has_eq_function = False
|
60 |
+
|
61 |
+
if eq is not None:
|
62 |
+
has_eq_function = True
|
63 |
+
body["__eq__"] = _make_operator("eq", eq)
|
64 |
+
body["__ne__"] = _make_ne()
|
65 |
+
|
66 |
+
if lt is not None:
|
67 |
+
num_order_functions += 1
|
68 |
+
body["__lt__"] = _make_operator("lt", lt)
|
69 |
+
|
70 |
+
if le is not None:
|
71 |
+
num_order_functions += 1
|
72 |
+
body["__le__"] = _make_operator("le", le)
|
73 |
+
|
74 |
+
if gt is not None:
|
75 |
+
num_order_functions += 1
|
76 |
+
body["__gt__"] = _make_operator("gt", gt)
|
77 |
+
|
78 |
+
if ge is not None:
|
79 |
+
num_order_functions += 1
|
80 |
+
body["__ge__"] = _make_operator("ge", ge)
|
81 |
+
|
82 |
+
type_ = types.new_class(
|
83 |
+
class_name, (object,), {}, lambda ns: ns.update(body)
|
84 |
+
)
|
85 |
+
|
86 |
+
# Add same type requirement.
|
87 |
+
if require_same_type:
|
88 |
+
type_._requirements.append(_check_same_type)
|
89 |
+
|
90 |
+
# Add total ordering if at least one operation was defined.
|
91 |
+
if 0 < num_order_functions < 4:
|
92 |
+
if not has_eq_function:
|
93 |
+
# functools.total_ordering requires __eq__ to be defined,
|
94 |
+
# so raise early error here to keep a nice stack.
|
95 |
+
msg = "eq must be define is order to complete ordering from lt, le, gt, ge."
|
96 |
+
raise ValueError(msg)
|
97 |
+
type_ = functools.total_ordering(type_)
|
98 |
+
|
99 |
+
return type_
|
100 |
+
|
101 |
+
|
102 |
+
def _make_init():
|
103 |
+
"""
|
104 |
+
Create __init__ method.
|
105 |
+
"""
|
106 |
+
|
107 |
+
def __init__(self, value):
|
108 |
+
"""
|
109 |
+
Initialize object with *value*.
|
110 |
+
"""
|
111 |
+
self.value = value
|
112 |
+
|
113 |
+
return __init__
|
114 |
+
|
115 |
+
|
116 |
+
def _make_operator(name, func):
|
117 |
+
"""
|
118 |
+
Create operator method.
|
119 |
+
"""
|
120 |
+
|
121 |
+
def method(self, other):
|
122 |
+
if not self._is_comparable_to(other):
|
123 |
+
return NotImplemented
|
124 |
+
|
125 |
+
result = func(self.value, other.value)
|
126 |
+
if result is NotImplemented:
|
127 |
+
return NotImplemented
|
128 |
+
|
129 |
+
return result
|
130 |
+
|
131 |
+
method.__name__ = f"__{name}__"
|
132 |
+
method.__doc__ = (
|
133 |
+
f"Return a {_operation_names[name]} b. Computed by attrs."
|
134 |
+
)
|
135 |
+
|
136 |
+
return method
|
137 |
+
|
138 |
+
|
139 |
+
def _is_comparable_to(self, other):
|
140 |
+
"""
|
141 |
+
Check whether `other` is comparable to `self`.
|
142 |
+
"""
|
143 |
+
return all(func(self, other) for func in self._requirements)
|
144 |
+
|
145 |
+
|
146 |
+
def _check_same_type(self, other):
|
147 |
+
"""
|
148 |
+
Return True if *self* and *other* are of the same type, False otherwise.
|
149 |
+
"""
|
150 |
+
return other.value.__class__ is self.value.__class__
|
llmeval-env/lib/python3.10/site-packages/attr/_cmp.pyi
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Callable, Optional, Type
|
2 |
+
|
3 |
+
_CompareWithType = Callable[[Any, Any], bool]
|
4 |
+
|
5 |
+
def cmp_using(
|
6 |
+
eq: Optional[_CompareWithType] = ...,
|
7 |
+
lt: Optional[_CompareWithType] = ...,
|
8 |
+
le: Optional[_CompareWithType] = ...,
|
9 |
+
gt: Optional[_CompareWithType] = ...,
|
10 |
+
ge: Optional[_CompareWithType] = ...,
|
11 |
+
require_same_type: bool = ...,
|
12 |
+
class_name: str = ...,
|
13 |
+
) -> Type: ...
|
llmeval-env/lib/python3.10/site-packages/attr/_compat.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
import inspect
|
4 |
+
import platform
|
5 |
+
import sys
|
6 |
+
import threading
|
7 |
+
|
8 |
+
from collections.abc import Mapping, Sequence # noqa: F401
|
9 |
+
from typing import _GenericAlias
|
10 |
+
|
11 |
+
|
12 |
+
PYPY = platform.python_implementation() == "PyPy"
|
13 |
+
PY_3_8_PLUS = sys.version_info[:2] >= (3, 8)
|
14 |
+
PY_3_9_PLUS = sys.version_info[:2] >= (3, 9)
|
15 |
+
PY310 = sys.version_info[:2] >= (3, 10)
|
16 |
+
PY_3_12_PLUS = sys.version_info[:2] >= (3, 12)
|
17 |
+
|
18 |
+
|
19 |
+
if sys.version_info < (3, 8):
|
20 |
+
try:
|
21 |
+
from typing_extensions import Protocol
|
22 |
+
except ImportError: # pragma: no cover
|
23 |
+
Protocol = object
|
24 |
+
else:
|
25 |
+
from typing import Protocol # noqa: F401
|
26 |
+
|
27 |
+
|
28 |
+
class _AnnotationExtractor:
|
29 |
+
"""
|
30 |
+
Extract type annotations from a callable, returning None whenever there
|
31 |
+
is none.
|
32 |
+
"""
|
33 |
+
|
34 |
+
__slots__ = ["sig"]
|
35 |
+
|
36 |
+
def __init__(self, callable):
|
37 |
+
try:
|
38 |
+
self.sig = inspect.signature(callable)
|
39 |
+
except (ValueError, TypeError): # inspect failed
|
40 |
+
self.sig = None
|
41 |
+
|
42 |
+
def get_first_param_type(self):
|
43 |
+
"""
|
44 |
+
Return the type annotation of the first argument if it's not empty.
|
45 |
+
"""
|
46 |
+
if not self.sig:
|
47 |
+
return None
|
48 |
+
|
49 |
+
params = list(self.sig.parameters.values())
|
50 |
+
if params and params[0].annotation is not inspect.Parameter.empty:
|
51 |
+
return params[0].annotation
|
52 |
+
|
53 |
+
return None
|
54 |
+
|
55 |
+
def get_return_type(self):
|
56 |
+
"""
|
57 |
+
Return the return type if it's not empty.
|
58 |
+
"""
|
59 |
+
if (
|
60 |
+
self.sig
|
61 |
+
and self.sig.return_annotation is not inspect.Signature.empty
|
62 |
+
):
|
63 |
+
return self.sig.return_annotation
|
64 |
+
|
65 |
+
return None
|
66 |
+
|
67 |
+
|
68 |
+
# Thread-local global to track attrs instances which are already being repr'd.
|
69 |
+
# This is needed because there is no other (thread-safe) way to pass info
|
70 |
+
# about the instances that are already being repr'd through the call stack
|
71 |
+
# in order to ensure we don't perform infinite recursion.
|
72 |
+
#
|
73 |
+
# For instance, if an instance contains a dict which contains that instance,
|
74 |
+
# we need to know that we're already repr'ing the outside instance from within
|
75 |
+
# the dict's repr() call.
|
76 |
+
#
|
77 |
+
# This lives here rather than in _make.py so that the functions in _make.py
|
78 |
+
# don't have a direct reference to the thread-local in their globals dict.
|
79 |
+
# If they have such a reference, it breaks cloudpickle.
|
80 |
+
repr_context = threading.local()
|
81 |
+
|
82 |
+
|
83 |
+
def get_generic_base(cl):
|
84 |
+
"""If this is a generic class (A[str]), return the generic base for it."""
|
85 |
+
if cl.__class__ is _GenericAlias:
|
86 |
+
return cl.__origin__
|
87 |
+
return None
|
llmeval-env/lib/python3.10/site-packages/attr/_config.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
__all__ = ["set_run_validators", "get_run_validators"]
|
4 |
+
|
5 |
+
_run_validators = True
|
6 |
+
|
7 |
+
|
8 |
+
def set_run_validators(run):
|
9 |
+
"""
|
10 |
+
Set whether or not validators are run. By default, they are run.
|
11 |
+
|
12 |
+
.. deprecated:: 21.3.0 It will not be removed, but it also will not be
|
13 |
+
moved to new ``attrs`` namespace. Use `attrs.validators.set_disabled()`
|
14 |
+
instead.
|
15 |
+
"""
|
16 |
+
if not isinstance(run, bool):
|
17 |
+
msg = "'run' must be bool."
|
18 |
+
raise TypeError(msg)
|
19 |
+
global _run_validators
|
20 |
+
_run_validators = run
|
21 |
+
|
22 |
+
|
23 |
+
def get_run_validators():
|
24 |
+
"""
|
25 |
+
Return whether or not validators are run.
|
26 |
+
|
27 |
+
.. deprecated:: 21.3.0 It will not be removed, but it also will not be
|
28 |
+
moved to new ``attrs`` namespace. Use `attrs.validators.get_disabled()`
|
29 |
+
instead.
|
30 |
+
"""
|
31 |
+
return _run_validators
|
llmeval-env/lib/python3.10/site-packages/attr/_funcs.py
ADDED
@@ -0,0 +1,483 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
|
4 |
+
import copy
|
5 |
+
|
6 |
+
from ._compat import PY_3_9_PLUS, get_generic_base
|
7 |
+
from ._make import NOTHING, _obj_setattr, fields
|
8 |
+
from .exceptions import AttrsAttributeNotFoundError
|
9 |
+
|
10 |
+
|
11 |
+
def asdict(
|
12 |
+
inst,
|
13 |
+
recurse=True,
|
14 |
+
filter=None,
|
15 |
+
dict_factory=dict,
|
16 |
+
retain_collection_types=False,
|
17 |
+
value_serializer=None,
|
18 |
+
):
|
19 |
+
"""
|
20 |
+
Return the *attrs* attribute values of *inst* as a dict.
|
21 |
+
|
22 |
+
Optionally recurse into other *attrs*-decorated classes.
|
23 |
+
|
24 |
+
:param inst: Instance of an *attrs*-decorated class.
|
25 |
+
:param bool recurse: Recurse into classes that are also
|
26 |
+
*attrs*-decorated.
|
27 |
+
:param callable filter: A callable whose return code determines whether an
|
28 |
+
attribute or element is included (``True``) or dropped (``False``). Is
|
29 |
+
called with the `attrs.Attribute` as the first argument and the
|
30 |
+
value as the second argument.
|
31 |
+
:param callable dict_factory: A callable to produce dictionaries from. For
|
32 |
+
example, to produce ordered dictionaries instead of normal Python
|
33 |
+
dictionaries, pass in ``collections.OrderedDict``.
|
34 |
+
:param bool retain_collection_types: Do not convert to ``list`` when
|
35 |
+
encountering an attribute whose type is ``tuple`` or ``set``. Only
|
36 |
+
meaningful if ``recurse`` is ``True``.
|
37 |
+
:param Optional[callable] value_serializer: A hook that is called for every
|
38 |
+
attribute or dict key/value. It receives the current instance, field
|
39 |
+
and value and must return the (updated) value. The hook is run *after*
|
40 |
+
the optional *filter* has been applied.
|
41 |
+
|
42 |
+
:rtype: return type of *dict_factory*
|
43 |
+
|
44 |
+
:raise attrs.exceptions.NotAnAttrsClassError: If *cls* is not an *attrs*
|
45 |
+
class.
|
46 |
+
|
47 |
+
.. versionadded:: 16.0.0 *dict_factory*
|
48 |
+
.. versionadded:: 16.1.0 *retain_collection_types*
|
49 |
+
.. versionadded:: 20.3.0 *value_serializer*
|
50 |
+
.. versionadded:: 21.3.0 If a dict has a collection for a key, it is
|
51 |
+
serialized as a tuple.
|
52 |
+
"""
|
53 |
+
attrs = fields(inst.__class__)
|
54 |
+
rv = dict_factory()
|
55 |
+
for a in attrs:
|
56 |
+
v = getattr(inst, a.name)
|
57 |
+
if filter is not None and not filter(a, v):
|
58 |
+
continue
|
59 |
+
|
60 |
+
if value_serializer is not None:
|
61 |
+
v = value_serializer(inst, a, v)
|
62 |
+
|
63 |
+
if recurse is True:
|
64 |
+
if has(v.__class__):
|
65 |
+
rv[a.name] = asdict(
|
66 |
+
v,
|
67 |
+
recurse=True,
|
68 |
+
filter=filter,
|
69 |
+
dict_factory=dict_factory,
|
70 |
+
retain_collection_types=retain_collection_types,
|
71 |
+
value_serializer=value_serializer,
|
72 |
+
)
|
73 |
+
elif isinstance(v, (tuple, list, set, frozenset)):
|
74 |
+
cf = v.__class__ if retain_collection_types is True else list
|
75 |
+
items = [
|
76 |
+
_asdict_anything(
|
77 |
+
i,
|
78 |
+
is_key=False,
|
79 |
+
filter=filter,
|
80 |
+
dict_factory=dict_factory,
|
81 |
+
retain_collection_types=retain_collection_types,
|
82 |
+
value_serializer=value_serializer,
|
83 |
+
)
|
84 |
+
for i in v
|
85 |
+
]
|
86 |
+
try:
|
87 |
+
rv[a.name] = cf(items)
|
88 |
+
except TypeError:
|
89 |
+
if not issubclass(cf, tuple):
|
90 |
+
raise
|
91 |
+
# Workaround for TypeError: cf.__new__() missing 1 required
|
92 |
+
# positional argument (which appears, for a namedturle)
|
93 |
+
rv[a.name] = cf(*items)
|
94 |
+
elif isinstance(v, dict):
|
95 |
+
df = dict_factory
|
96 |
+
rv[a.name] = df(
|
97 |
+
(
|
98 |
+
_asdict_anything(
|
99 |
+
kk,
|
100 |
+
is_key=True,
|
101 |
+
filter=filter,
|
102 |
+
dict_factory=df,
|
103 |
+
retain_collection_types=retain_collection_types,
|
104 |
+
value_serializer=value_serializer,
|
105 |
+
),
|
106 |
+
_asdict_anything(
|
107 |
+
vv,
|
108 |
+
is_key=False,
|
109 |
+
filter=filter,
|
110 |
+
dict_factory=df,
|
111 |
+
retain_collection_types=retain_collection_types,
|
112 |
+
value_serializer=value_serializer,
|
113 |
+
),
|
114 |
+
)
|
115 |
+
for kk, vv in v.items()
|
116 |
+
)
|
117 |
+
else:
|
118 |
+
rv[a.name] = v
|
119 |
+
else:
|
120 |
+
rv[a.name] = v
|
121 |
+
return rv
|
122 |
+
|
123 |
+
|
124 |
+
def _asdict_anything(
|
125 |
+
val,
|
126 |
+
is_key,
|
127 |
+
filter,
|
128 |
+
dict_factory,
|
129 |
+
retain_collection_types,
|
130 |
+
value_serializer,
|
131 |
+
):
|
132 |
+
"""
|
133 |
+
``asdict`` only works on attrs instances, this works on anything.
|
134 |
+
"""
|
135 |
+
if getattr(val.__class__, "__attrs_attrs__", None) is not None:
|
136 |
+
# Attrs class.
|
137 |
+
rv = asdict(
|
138 |
+
val,
|
139 |
+
recurse=True,
|
140 |
+
filter=filter,
|
141 |
+
dict_factory=dict_factory,
|
142 |
+
retain_collection_types=retain_collection_types,
|
143 |
+
value_serializer=value_serializer,
|
144 |
+
)
|
145 |
+
elif isinstance(val, (tuple, list, set, frozenset)):
|
146 |
+
if retain_collection_types is True:
|
147 |
+
cf = val.__class__
|
148 |
+
elif is_key:
|
149 |
+
cf = tuple
|
150 |
+
else:
|
151 |
+
cf = list
|
152 |
+
|
153 |
+
rv = cf(
|
154 |
+
[
|
155 |
+
_asdict_anything(
|
156 |
+
i,
|
157 |
+
is_key=False,
|
158 |
+
filter=filter,
|
159 |
+
dict_factory=dict_factory,
|
160 |
+
retain_collection_types=retain_collection_types,
|
161 |
+
value_serializer=value_serializer,
|
162 |
+
)
|
163 |
+
for i in val
|
164 |
+
]
|
165 |
+
)
|
166 |
+
elif isinstance(val, dict):
|
167 |
+
df = dict_factory
|
168 |
+
rv = df(
|
169 |
+
(
|
170 |
+
_asdict_anything(
|
171 |
+
kk,
|
172 |
+
is_key=True,
|
173 |
+
filter=filter,
|
174 |
+
dict_factory=df,
|
175 |
+
retain_collection_types=retain_collection_types,
|
176 |
+
value_serializer=value_serializer,
|
177 |
+
),
|
178 |
+
_asdict_anything(
|
179 |
+
vv,
|
180 |
+
is_key=False,
|
181 |
+
filter=filter,
|
182 |
+
dict_factory=df,
|
183 |
+
retain_collection_types=retain_collection_types,
|
184 |
+
value_serializer=value_serializer,
|
185 |
+
),
|
186 |
+
)
|
187 |
+
for kk, vv in val.items()
|
188 |
+
)
|
189 |
+
else:
|
190 |
+
rv = val
|
191 |
+
if value_serializer is not None:
|
192 |
+
rv = value_serializer(None, None, rv)
|
193 |
+
|
194 |
+
return rv
|
195 |
+
|
196 |
+
|
197 |
+
def astuple(
|
198 |
+
inst,
|
199 |
+
recurse=True,
|
200 |
+
filter=None,
|
201 |
+
tuple_factory=tuple,
|
202 |
+
retain_collection_types=False,
|
203 |
+
):
|
204 |
+
"""
|
205 |
+
Return the *attrs* attribute values of *inst* as a tuple.
|
206 |
+
|
207 |
+
Optionally recurse into other *attrs*-decorated classes.
|
208 |
+
|
209 |
+
:param inst: Instance of an *attrs*-decorated class.
|
210 |
+
:param bool recurse: Recurse into classes that are also
|
211 |
+
*attrs*-decorated.
|
212 |
+
:param callable filter: A callable whose return code determines whether an
|
213 |
+
attribute or element is included (``True``) or dropped (``False``). Is
|
214 |
+
called with the `attrs.Attribute` as the first argument and the
|
215 |
+
value as the second argument.
|
216 |
+
:param callable tuple_factory: A callable to produce tuples from. For
|
217 |
+
example, to produce lists instead of tuples.
|
218 |
+
:param bool retain_collection_types: Do not convert to ``list``
|
219 |
+
or ``dict`` when encountering an attribute which type is
|
220 |
+
``tuple``, ``dict`` or ``set``. Only meaningful if ``recurse`` is
|
221 |
+
``True``.
|
222 |
+
|
223 |
+
:rtype: return type of *tuple_factory*
|
224 |
+
|
225 |
+
:raise attrs.exceptions.NotAnAttrsClassError: If *cls* is not an *attrs*
|
226 |
+
class.
|
227 |
+
|
228 |
+
.. versionadded:: 16.2.0
|
229 |
+
"""
|
230 |
+
attrs = fields(inst.__class__)
|
231 |
+
rv = []
|
232 |
+
retain = retain_collection_types # Very long. :/
|
233 |
+
for a in attrs:
|
234 |
+
v = getattr(inst, a.name)
|
235 |
+
if filter is not None and not filter(a, v):
|
236 |
+
continue
|
237 |
+
if recurse is True:
|
238 |
+
if has(v.__class__):
|
239 |
+
rv.append(
|
240 |
+
astuple(
|
241 |
+
v,
|
242 |
+
recurse=True,
|
243 |
+
filter=filter,
|
244 |
+
tuple_factory=tuple_factory,
|
245 |
+
retain_collection_types=retain,
|
246 |
+
)
|
247 |
+
)
|
248 |
+
elif isinstance(v, (tuple, list, set, frozenset)):
|
249 |
+
cf = v.__class__ if retain is True else list
|
250 |
+
items = [
|
251 |
+
astuple(
|
252 |
+
j,
|
253 |
+
recurse=True,
|
254 |
+
filter=filter,
|
255 |
+
tuple_factory=tuple_factory,
|
256 |
+
retain_collection_types=retain,
|
257 |
+
)
|
258 |
+
if has(j.__class__)
|
259 |
+
else j
|
260 |
+
for j in v
|
261 |
+
]
|
262 |
+
try:
|
263 |
+
rv.append(cf(items))
|
264 |
+
except TypeError:
|
265 |
+
if not issubclass(cf, tuple):
|
266 |
+
raise
|
267 |
+
# Workaround for TypeError: cf.__new__() missing 1 required
|
268 |
+
# positional argument (which appears, for a namedturle)
|
269 |
+
rv.append(cf(*items))
|
270 |
+
elif isinstance(v, dict):
|
271 |
+
df = v.__class__ if retain is True else dict
|
272 |
+
rv.append(
|
273 |
+
df(
|
274 |
+
(
|
275 |
+
astuple(
|
276 |
+
kk,
|
277 |
+
tuple_factory=tuple_factory,
|
278 |
+
retain_collection_types=retain,
|
279 |
+
)
|
280 |
+
if has(kk.__class__)
|
281 |
+
else kk,
|
282 |
+
astuple(
|
283 |
+
vv,
|
284 |
+
tuple_factory=tuple_factory,
|
285 |
+
retain_collection_types=retain,
|
286 |
+
)
|
287 |
+
if has(vv.__class__)
|
288 |
+
else vv,
|
289 |
+
)
|
290 |
+
for kk, vv in v.items()
|
291 |
+
)
|
292 |
+
)
|
293 |
+
else:
|
294 |
+
rv.append(v)
|
295 |
+
else:
|
296 |
+
rv.append(v)
|
297 |
+
|
298 |
+
return rv if tuple_factory is list else tuple_factory(rv)
|
299 |
+
|
300 |
+
|
301 |
+
def has(cls):
|
302 |
+
"""
|
303 |
+
Check whether *cls* is a class with *attrs* attributes.
|
304 |
+
|
305 |
+
:param type cls: Class to introspect.
|
306 |
+
:raise TypeError: If *cls* is not a class.
|
307 |
+
|
308 |
+
:rtype: bool
|
309 |
+
"""
|
310 |
+
attrs = getattr(cls, "__attrs_attrs__", None)
|
311 |
+
if attrs is not None:
|
312 |
+
return True
|
313 |
+
|
314 |
+
# No attrs, maybe it's a specialized generic (A[str])?
|
315 |
+
generic_base = get_generic_base(cls)
|
316 |
+
if generic_base is not None:
|
317 |
+
generic_attrs = getattr(generic_base, "__attrs_attrs__", None)
|
318 |
+
if generic_attrs is not None:
|
319 |
+
# Stick it on here for speed next time.
|
320 |
+
cls.__attrs_attrs__ = generic_attrs
|
321 |
+
return generic_attrs is not None
|
322 |
+
return False
|
323 |
+
|
324 |
+
|
325 |
+
def assoc(inst, **changes):
|
326 |
+
"""
|
327 |
+
Copy *inst* and apply *changes*.
|
328 |
+
|
329 |
+
This is different from `evolve` that applies the changes to the arguments
|
330 |
+
that create the new instance.
|
331 |
+
|
332 |
+
`evolve`'s behavior is preferable, but there are `edge cases`_ where it
|
333 |
+
doesn't work. Therefore `assoc` is deprecated, but will not be removed.
|
334 |
+
|
335 |
+
.. _`edge cases`: https://github.com/python-attrs/attrs/issues/251
|
336 |
+
|
337 |
+
:param inst: Instance of a class with *attrs* attributes.
|
338 |
+
:param changes: Keyword changes in the new copy.
|
339 |
+
|
340 |
+
:return: A copy of inst with *changes* incorporated.
|
341 |
+
|
342 |
+
:raise attrs.exceptions.AttrsAttributeNotFoundError: If *attr_name*
|
343 |
+
couldn't be found on *cls*.
|
344 |
+
:raise attrs.exceptions.NotAnAttrsClassError: If *cls* is not an *attrs*
|
345 |
+
class.
|
346 |
+
|
347 |
+
.. deprecated:: 17.1.0
|
348 |
+
Use `attrs.evolve` instead if you can.
|
349 |
+
This function will not be removed du to the slightly different approach
|
350 |
+
compared to `attrs.evolve`.
|
351 |
+
"""
|
352 |
+
new = copy.copy(inst)
|
353 |
+
attrs = fields(inst.__class__)
|
354 |
+
for k, v in changes.items():
|
355 |
+
a = getattr(attrs, k, NOTHING)
|
356 |
+
if a is NOTHING:
|
357 |
+
msg = f"{k} is not an attrs attribute on {new.__class__}."
|
358 |
+
raise AttrsAttributeNotFoundError(msg)
|
359 |
+
_obj_setattr(new, k, v)
|
360 |
+
return new
|
361 |
+
|
362 |
+
|
363 |
+
def evolve(*args, **changes):
|
364 |
+
"""
|
365 |
+
Create a new instance, based on the first positional argument with
|
366 |
+
*changes* applied.
|
367 |
+
|
368 |
+
:param inst: Instance of a class with *attrs* attributes.
|
369 |
+
:param changes: Keyword changes in the new copy.
|
370 |
+
|
371 |
+
:return: A copy of inst with *changes* incorporated.
|
372 |
+
|
373 |
+
:raise TypeError: If *attr_name* couldn't be found in the class
|
374 |
+
``__init__``.
|
375 |
+
:raise attrs.exceptions.NotAnAttrsClassError: If *cls* is not an *attrs*
|
376 |
+
class.
|
377 |
+
|
378 |
+
.. versionadded:: 17.1.0
|
379 |
+
.. deprecated:: 23.1.0
|
380 |
+
It is now deprecated to pass the instance using the keyword argument
|
381 |
+
*inst*. It will raise a warning until at least April 2024, after which
|
382 |
+
it will become an error. Always pass the instance as a positional
|
383 |
+
argument.
|
384 |
+
"""
|
385 |
+
# Try to get instance by positional argument first.
|
386 |
+
# Use changes otherwise and warn it'll break.
|
387 |
+
if args:
|
388 |
+
try:
|
389 |
+
(inst,) = args
|
390 |
+
except ValueError:
|
391 |
+
msg = f"evolve() takes 1 positional argument, but {len(args)} were given"
|
392 |
+
raise TypeError(msg) from None
|
393 |
+
else:
|
394 |
+
try:
|
395 |
+
inst = changes.pop("inst")
|
396 |
+
except KeyError:
|
397 |
+
msg = "evolve() missing 1 required positional argument: 'inst'"
|
398 |
+
raise TypeError(msg) from None
|
399 |
+
|
400 |
+
import warnings
|
401 |
+
|
402 |
+
warnings.warn(
|
403 |
+
"Passing the instance per keyword argument is deprecated and "
|
404 |
+
"will stop working in, or after, April 2024.",
|
405 |
+
DeprecationWarning,
|
406 |
+
stacklevel=2,
|
407 |
+
)
|
408 |
+
|
409 |
+
cls = inst.__class__
|
410 |
+
attrs = fields(cls)
|
411 |
+
for a in attrs:
|
412 |
+
if not a.init:
|
413 |
+
continue
|
414 |
+
attr_name = a.name # To deal with private attributes.
|
415 |
+
init_name = a.alias
|
416 |
+
if init_name not in changes:
|
417 |
+
changes[init_name] = getattr(inst, attr_name)
|
418 |
+
|
419 |
+
return cls(**changes)
|
420 |
+
|
421 |
+
|
422 |
+
def resolve_types(
|
423 |
+
cls, globalns=None, localns=None, attribs=None, include_extras=True
|
424 |
+
):
|
425 |
+
"""
|
426 |
+
Resolve any strings and forward annotations in type annotations.
|
427 |
+
|
428 |
+
This is only required if you need concrete types in `Attribute`'s *type*
|
429 |
+
field. In other words, you don't need to resolve your types if you only
|
430 |
+
use them for static type checking.
|
431 |
+
|
432 |
+
With no arguments, names will be looked up in the module in which the class
|
433 |
+
was created. If this is not what you want, e.g. if the name only exists
|
434 |
+
inside a method, you may pass *globalns* or *localns* to specify other
|
435 |
+
dictionaries in which to look up these names. See the docs of
|
436 |
+
`typing.get_type_hints` for more details.
|
437 |
+
|
438 |
+
:param type cls: Class to resolve.
|
439 |
+
:param Optional[dict] globalns: Dictionary containing global variables.
|
440 |
+
:param Optional[dict] localns: Dictionary containing local variables.
|
441 |
+
:param Optional[list] attribs: List of attribs for the given class.
|
442 |
+
This is necessary when calling from inside a ``field_transformer``
|
443 |
+
since *cls* is not an *attrs* class yet.
|
444 |
+
:param bool include_extras: Resolve more accurately, if possible.
|
445 |
+
Pass ``include_extras`` to ``typing.get_hints``, if supported by the
|
446 |
+
typing module. On supported Python versions (3.9+), this resolves the
|
447 |
+
types more accurately.
|
448 |
+
|
449 |
+
:raise TypeError: If *cls* is not a class.
|
450 |
+
:raise attrs.exceptions.NotAnAttrsClassError: If *cls* is not an *attrs*
|
451 |
+
class and you didn't pass any attribs.
|
452 |
+
:raise NameError: If types cannot be resolved because of missing variables.
|
453 |
+
|
454 |
+
:returns: *cls* so you can use this function also as a class decorator.
|
455 |
+
Please note that you have to apply it **after** `attrs.define`. That
|
456 |
+
means the decorator has to come in the line **before** `attrs.define`.
|
457 |
+
|
458 |
+
.. versionadded:: 20.1.0
|
459 |
+
.. versionadded:: 21.1.0 *attribs*
|
460 |
+
.. versionadded:: 23.1.0 *include_extras*
|
461 |
+
|
462 |
+
"""
|
463 |
+
# Since calling get_type_hints is expensive we cache whether we've
|
464 |
+
# done it already.
|
465 |
+
if getattr(cls, "__attrs_types_resolved__", None) != cls:
|
466 |
+
import typing
|
467 |
+
|
468 |
+
kwargs = {"globalns": globalns, "localns": localns}
|
469 |
+
|
470 |
+
if PY_3_9_PLUS:
|
471 |
+
kwargs["include_extras"] = include_extras
|
472 |
+
|
473 |
+
hints = typing.get_type_hints(cls, **kwargs)
|
474 |
+
for field in fields(cls) if attribs is None else attribs:
|
475 |
+
if field.name in hints:
|
476 |
+
# Since fields have been frozen we must work around it.
|
477 |
+
_obj_setattr(field, "type", hints[field.name])
|
478 |
+
# We store the class we resolved so that subclasses know they haven't
|
479 |
+
# been resolved.
|
480 |
+
cls.__attrs_types_resolved__ = cls
|
481 |
+
|
482 |
+
# Return the class so you can use it as a decorator too.
|
483 |
+
return cls
|
llmeval-env/lib/python3.10/site-packages/attr/_make.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|
llmeval-env/lib/python3.10/site-packages/attr/_next_gen.py
ADDED
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
"""
|
4 |
+
These are keyword-only APIs that call `attr.s` and `attr.ib` with different
|
5 |
+
default values.
|
6 |
+
"""
|
7 |
+
|
8 |
+
|
9 |
+
from functools import partial
|
10 |
+
|
11 |
+
from . import setters
|
12 |
+
from ._funcs import asdict as _asdict
|
13 |
+
from ._funcs import astuple as _astuple
|
14 |
+
from ._make import (
|
15 |
+
NOTHING,
|
16 |
+
_frozen_setattrs,
|
17 |
+
_ng_default_on_setattr,
|
18 |
+
attrib,
|
19 |
+
attrs,
|
20 |
+
)
|
21 |
+
from .exceptions import UnannotatedAttributeError
|
22 |
+
|
23 |
+
|
24 |
+
def define(
|
25 |
+
maybe_cls=None,
|
26 |
+
*,
|
27 |
+
these=None,
|
28 |
+
repr=None,
|
29 |
+
unsafe_hash=None,
|
30 |
+
hash=None,
|
31 |
+
init=None,
|
32 |
+
slots=True,
|
33 |
+
frozen=False,
|
34 |
+
weakref_slot=True,
|
35 |
+
str=False,
|
36 |
+
auto_attribs=None,
|
37 |
+
kw_only=False,
|
38 |
+
cache_hash=False,
|
39 |
+
auto_exc=True,
|
40 |
+
eq=None,
|
41 |
+
order=False,
|
42 |
+
auto_detect=True,
|
43 |
+
getstate_setstate=None,
|
44 |
+
on_setattr=None,
|
45 |
+
field_transformer=None,
|
46 |
+
match_args=True,
|
47 |
+
):
|
48 |
+
r"""
|
49 |
+
Define an *attrs* class.
|
50 |
+
|
51 |
+
Differences to the classic `attr.s` that it uses underneath:
|
52 |
+
|
53 |
+
- Automatically detect whether or not *auto_attribs* should be `True` (c.f.
|
54 |
+
*auto_attribs* parameter).
|
55 |
+
- Converters and validators run when attributes are set by default -- if
|
56 |
+
*frozen* is `False`.
|
57 |
+
- *slots=True*
|
58 |
+
|
59 |
+
.. caution::
|
60 |
+
|
61 |
+
Usually this has only upsides and few visible effects in everyday
|
62 |
+
programming. But it *can* lead to some surprising behaviors, so please
|
63 |
+
make sure to read :term:`slotted classes`.
|
64 |
+
- *auto_exc=True*
|
65 |
+
- *auto_detect=True*
|
66 |
+
- *order=False*
|
67 |
+
- Some options that were only relevant on Python 2 or were kept around for
|
68 |
+
backwards-compatibility have been removed.
|
69 |
+
|
70 |
+
Please note that these are all defaults and you can change them as you
|
71 |
+
wish.
|
72 |
+
|
73 |
+
:param Optional[bool] auto_attribs: If set to `True` or `False`, it behaves
|
74 |
+
exactly like `attr.s`. If left `None`, `attr.s` will try to guess:
|
75 |
+
|
76 |
+
1. If any attributes are annotated and no unannotated `attrs.fields`\ s
|
77 |
+
are found, it assumes *auto_attribs=True*.
|
78 |
+
2. Otherwise it assumes *auto_attribs=False* and tries to collect
|
79 |
+
`attrs.fields`\ s.
|
80 |
+
|
81 |
+
For now, please refer to `attr.s` for the rest of the parameters.
|
82 |
+
|
83 |
+
.. versionadded:: 20.1.0
|
84 |
+
.. versionchanged:: 21.3.0 Converters are also run ``on_setattr``.
|
85 |
+
.. versionadded:: 22.2.0
|
86 |
+
*unsafe_hash* as an alias for *hash* (for :pep:`681` compliance).
|
87 |
+
"""
|
88 |
+
|
89 |
+
def do_it(cls, auto_attribs):
|
90 |
+
return attrs(
|
91 |
+
maybe_cls=cls,
|
92 |
+
these=these,
|
93 |
+
repr=repr,
|
94 |
+
hash=hash,
|
95 |
+
unsafe_hash=unsafe_hash,
|
96 |
+
init=init,
|
97 |
+
slots=slots,
|
98 |
+
frozen=frozen,
|
99 |
+
weakref_slot=weakref_slot,
|
100 |
+
str=str,
|
101 |
+
auto_attribs=auto_attribs,
|
102 |
+
kw_only=kw_only,
|
103 |
+
cache_hash=cache_hash,
|
104 |
+
auto_exc=auto_exc,
|
105 |
+
eq=eq,
|
106 |
+
order=order,
|
107 |
+
auto_detect=auto_detect,
|
108 |
+
collect_by_mro=True,
|
109 |
+
getstate_setstate=getstate_setstate,
|
110 |
+
on_setattr=on_setattr,
|
111 |
+
field_transformer=field_transformer,
|
112 |
+
match_args=match_args,
|
113 |
+
)
|
114 |
+
|
115 |
+
def wrap(cls):
|
116 |
+
"""
|
117 |
+
Making this a wrapper ensures this code runs during class creation.
|
118 |
+
|
119 |
+
We also ensure that frozen-ness of classes is inherited.
|
120 |
+
"""
|
121 |
+
nonlocal frozen, on_setattr
|
122 |
+
|
123 |
+
had_on_setattr = on_setattr not in (None, setters.NO_OP)
|
124 |
+
|
125 |
+
# By default, mutable classes convert & validate on setattr.
|
126 |
+
if frozen is False and on_setattr is None:
|
127 |
+
on_setattr = _ng_default_on_setattr
|
128 |
+
|
129 |
+
# However, if we subclass a frozen class, we inherit the immutability
|
130 |
+
# and disable on_setattr.
|
131 |
+
for base_cls in cls.__bases__:
|
132 |
+
if base_cls.__setattr__ is _frozen_setattrs:
|
133 |
+
if had_on_setattr:
|
134 |
+
msg = "Frozen classes can't use on_setattr (frozen-ness was inherited)."
|
135 |
+
raise ValueError(msg)
|
136 |
+
|
137 |
+
on_setattr = setters.NO_OP
|
138 |
+
break
|
139 |
+
|
140 |
+
if auto_attribs is not None:
|
141 |
+
return do_it(cls, auto_attribs)
|
142 |
+
|
143 |
+
try:
|
144 |
+
return do_it(cls, True)
|
145 |
+
except UnannotatedAttributeError:
|
146 |
+
return do_it(cls, False)
|
147 |
+
|
148 |
+
# maybe_cls's type depends on the usage of the decorator. It's a class
|
149 |
+
# if it's used as `@attrs` but ``None`` if used as `@attrs()`.
|
150 |
+
if maybe_cls is None:
|
151 |
+
return wrap
|
152 |
+
|
153 |
+
return wrap(maybe_cls)
|
154 |
+
|
155 |
+
|
156 |
+
mutable = define
|
157 |
+
frozen = partial(define, frozen=True, on_setattr=None)
|
158 |
+
|
159 |
+
|
160 |
+
def field(
|
161 |
+
*,
|
162 |
+
default=NOTHING,
|
163 |
+
validator=None,
|
164 |
+
repr=True,
|
165 |
+
hash=None,
|
166 |
+
init=True,
|
167 |
+
metadata=None,
|
168 |
+
type=None,
|
169 |
+
converter=None,
|
170 |
+
factory=None,
|
171 |
+
kw_only=False,
|
172 |
+
eq=None,
|
173 |
+
order=None,
|
174 |
+
on_setattr=None,
|
175 |
+
alias=None,
|
176 |
+
):
|
177 |
+
"""
|
178 |
+
Identical to `attr.ib`, except keyword-only and with some arguments
|
179 |
+
removed.
|
180 |
+
|
181 |
+
.. versionadded:: 23.1.0
|
182 |
+
The *type* parameter has been re-added; mostly for `attrs.make_class`.
|
183 |
+
Please note that type checkers ignore this metadata.
|
184 |
+
.. versionadded:: 20.1.0
|
185 |
+
"""
|
186 |
+
return attrib(
|
187 |
+
default=default,
|
188 |
+
validator=validator,
|
189 |
+
repr=repr,
|
190 |
+
hash=hash,
|
191 |
+
init=init,
|
192 |
+
metadata=metadata,
|
193 |
+
type=type,
|
194 |
+
converter=converter,
|
195 |
+
factory=factory,
|
196 |
+
kw_only=kw_only,
|
197 |
+
eq=eq,
|
198 |
+
order=order,
|
199 |
+
on_setattr=on_setattr,
|
200 |
+
alias=alias,
|
201 |
+
)
|
202 |
+
|
203 |
+
|
204 |
+
def asdict(inst, *, recurse=True, filter=None, value_serializer=None):
|
205 |
+
"""
|
206 |
+
Same as `attr.asdict`, except that collections types are always retained
|
207 |
+
and dict is always used as *dict_factory*.
|
208 |
+
|
209 |
+
.. versionadded:: 21.3.0
|
210 |
+
"""
|
211 |
+
return _asdict(
|
212 |
+
inst=inst,
|
213 |
+
recurse=recurse,
|
214 |
+
filter=filter,
|
215 |
+
value_serializer=value_serializer,
|
216 |
+
retain_collection_types=True,
|
217 |
+
)
|
218 |
+
|
219 |
+
|
220 |
+
def astuple(inst, *, recurse=True, filter=None):
|
221 |
+
"""
|
222 |
+
Same as `attr.astuple`, except that collections types are always retained
|
223 |
+
and `tuple` is always used as the *tuple_factory*.
|
224 |
+
|
225 |
+
.. versionadded:: 21.3.0
|
226 |
+
"""
|
227 |
+
return _astuple(
|
228 |
+
inst=inst, recurse=recurse, filter=filter, retain_collection_types=True
|
229 |
+
)
|
llmeval-env/lib/python3.10/site-packages/attr/_typing_compat.pyi
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, ClassVar, Protocol
|
2 |
+
|
3 |
+
# MYPY is a special constant in mypy which works the same way as `TYPE_CHECKING`.
|
4 |
+
MYPY = False
|
5 |
+
|
6 |
+
if MYPY:
|
7 |
+
# A protocol to be able to statically accept an attrs class.
|
8 |
+
class AttrsInstance_(Protocol):
|
9 |
+
__attrs_attrs__: ClassVar[Any]
|
10 |
+
|
11 |
+
else:
|
12 |
+
# For type checkers without plug-in support use an empty protocol that
|
13 |
+
# will (hopefully) be combined into a union.
|
14 |
+
class AttrsInstance_(Protocol):
|
15 |
+
pass
|
llmeval-env/lib/python3.10/site-packages/attr/_version_info.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
|
4 |
+
from functools import total_ordering
|
5 |
+
|
6 |
+
from ._funcs import astuple
|
7 |
+
from ._make import attrib, attrs
|
8 |
+
|
9 |
+
|
10 |
+
@total_ordering
|
11 |
+
@attrs(eq=False, order=False, slots=True, frozen=True)
|
12 |
+
class VersionInfo:
|
13 |
+
"""
|
14 |
+
A version object that can be compared to tuple of length 1--4:
|
15 |
+
|
16 |
+
>>> attr.VersionInfo(19, 1, 0, "final") <= (19, 2)
|
17 |
+
True
|
18 |
+
>>> attr.VersionInfo(19, 1, 0, "final") < (19, 1, 1)
|
19 |
+
True
|
20 |
+
>>> vi = attr.VersionInfo(19, 2, 0, "final")
|
21 |
+
>>> vi < (19, 1, 1)
|
22 |
+
False
|
23 |
+
>>> vi < (19,)
|
24 |
+
False
|
25 |
+
>>> vi == (19, 2,)
|
26 |
+
True
|
27 |
+
>>> vi == (19, 2, 1)
|
28 |
+
False
|
29 |
+
|
30 |
+
.. versionadded:: 19.2
|
31 |
+
"""
|
32 |
+
|
33 |
+
year = attrib(type=int)
|
34 |
+
minor = attrib(type=int)
|
35 |
+
micro = attrib(type=int)
|
36 |
+
releaselevel = attrib(type=str)
|
37 |
+
|
38 |
+
@classmethod
|
39 |
+
def _from_version_string(cls, s):
|
40 |
+
"""
|
41 |
+
Parse *s* and return a _VersionInfo.
|
42 |
+
"""
|
43 |
+
v = s.split(".")
|
44 |
+
if len(v) == 3:
|
45 |
+
v.append("final")
|
46 |
+
|
47 |
+
return cls(
|
48 |
+
year=int(v[0]), minor=int(v[1]), micro=int(v[2]), releaselevel=v[3]
|
49 |
+
)
|
50 |
+
|
51 |
+
def _ensure_tuple(self, other):
|
52 |
+
"""
|
53 |
+
Ensure *other* is a tuple of a valid length.
|
54 |
+
|
55 |
+
Returns a possibly transformed *other* and ourselves as a tuple of
|
56 |
+
the same length as *other*.
|
57 |
+
"""
|
58 |
+
|
59 |
+
if self.__class__ is other.__class__:
|
60 |
+
other = astuple(other)
|
61 |
+
|
62 |
+
if not isinstance(other, tuple):
|
63 |
+
raise NotImplementedError
|
64 |
+
|
65 |
+
if not (1 <= len(other) <= 4):
|
66 |
+
raise NotImplementedError
|
67 |
+
|
68 |
+
return astuple(self)[: len(other)], other
|
69 |
+
|
70 |
+
def __eq__(self, other):
|
71 |
+
try:
|
72 |
+
us, them = self._ensure_tuple(other)
|
73 |
+
except NotImplementedError:
|
74 |
+
return NotImplemented
|
75 |
+
|
76 |
+
return us == them
|
77 |
+
|
78 |
+
def __lt__(self, other):
|
79 |
+
try:
|
80 |
+
us, them = self._ensure_tuple(other)
|
81 |
+
except NotImplementedError:
|
82 |
+
return NotImplemented
|
83 |
+
|
84 |
+
# Since alphabetically "dev0" < "final" < "post1" < "post2", we don't
|
85 |
+
# have to do anything special with releaselevel for now.
|
86 |
+
return us < them
|
llmeval-env/lib/python3.10/site-packages/attr/_version_info.pyi
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class VersionInfo:
|
2 |
+
@property
|
3 |
+
def year(self) -> int: ...
|
4 |
+
@property
|
5 |
+
def minor(self) -> int: ...
|
6 |
+
@property
|
7 |
+
def micro(self) -> int: ...
|
8 |
+
@property
|
9 |
+
def releaselevel(self) -> str: ...
|
llmeval-env/lib/python3.10/site-packages/attr/converters.py
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
"""
|
4 |
+
Commonly useful converters.
|
5 |
+
"""
|
6 |
+
|
7 |
+
|
8 |
+
import typing
|
9 |
+
|
10 |
+
from ._compat import _AnnotationExtractor
|
11 |
+
from ._make import NOTHING, Factory, pipe
|
12 |
+
|
13 |
+
|
14 |
+
__all__ = [
|
15 |
+
"default_if_none",
|
16 |
+
"optional",
|
17 |
+
"pipe",
|
18 |
+
"to_bool",
|
19 |
+
]
|
20 |
+
|
21 |
+
|
22 |
+
def optional(converter):
|
23 |
+
"""
|
24 |
+
A converter that allows an attribute to be optional. An optional attribute
|
25 |
+
is one which can be set to ``None``.
|
26 |
+
|
27 |
+
Type annotations will be inferred from the wrapped converter's, if it
|
28 |
+
has any.
|
29 |
+
|
30 |
+
:param callable converter: the converter that is used for non-``None``
|
31 |
+
values.
|
32 |
+
|
33 |
+
.. versionadded:: 17.1.0
|
34 |
+
"""
|
35 |
+
|
36 |
+
def optional_converter(val):
|
37 |
+
if val is None:
|
38 |
+
return None
|
39 |
+
return converter(val)
|
40 |
+
|
41 |
+
xtr = _AnnotationExtractor(converter)
|
42 |
+
|
43 |
+
t = xtr.get_first_param_type()
|
44 |
+
if t:
|
45 |
+
optional_converter.__annotations__["val"] = typing.Optional[t]
|
46 |
+
|
47 |
+
rt = xtr.get_return_type()
|
48 |
+
if rt:
|
49 |
+
optional_converter.__annotations__["return"] = typing.Optional[rt]
|
50 |
+
|
51 |
+
return optional_converter
|
52 |
+
|
53 |
+
|
54 |
+
def default_if_none(default=NOTHING, factory=None):
|
55 |
+
"""
|
56 |
+
A converter that allows to replace ``None`` values by *default* or the
|
57 |
+
result of *factory*.
|
58 |
+
|
59 |
+
:param default: Value to be used if ``None`` is passed. Passing an instance
|
60 |
+
of `attrs.Factory` is supported, however the ``takes_self`` option
|
61 |
+
is *not*.
|
62 |
+
:param callable factory: A callable that takes no parameters whose result
|
63 |
+
is used if ``None`` is passed.
|
64 |
+
|
65 |
+
:raises TypeError: If **neither** *default* or *factory* is passed.
|
66 |
+
:raises TypeError: If **both** *default* and *factory* are passed.
|
67 |
+
:raises ValueError: If an instance of `attrs.Factory` is passed with
|
68 |
+
``takes_self=True``.
|
69 |
+
|
70 |
+
.. versionadded:: 18.2.0
|
71 |
+
"""
|
72 |
+
if default is NOTHING and factory is None:
|
73 |
+
msg = "Must pass either `default` or `factory`."
|
74 |
+
raise TypeError(msg)
|
75 |
+
|
76 |
+
if default is not NOTHING and factory is not None:
|
77 |
+
msg = "Must pass either `default` or `factory` but not both."
|
78 |
+
raise TypeError(msg)
|
79 |
+
|
80 |
+
if factory is not None:
|
81 |
+
default = Factory(factory)
|
82 |
+
|
83 |
+
if isinstance(default, Factory):
|
84 |
+
if default.takes_self:
|
85 |
+
msg = "`takes_self` is not supported by default_if_none."
|
86 |
+
raise ValueError(msg)
|
87 |
+
|
88 |
+
def default_if_none_converter(val):
|
89 |
+
if val is not None:
|
90 |
+
return val
|
91 |
+
|
92 |
+
return default.factory()
|
93 |
+
|
94 |
+
else:
|
95 |
+
|
96 |
+
def default_if_none_converter(val):
|
97 |
+
if val is not None:
|
98 |
+
return val
|
99 |
+
|
100 |
+
return default
|
101 |
+
|
102 |
+
return default_if_none_converter
|
103 |
+
|
104 |
+
|
105 |
+
def to_bool(val):
|
106 |
+
"""
|
107 |
+
Convert "boolean" strings (e.g., from env. vars.) to real booleans.
|
108 |
+
|
109 |
+
Values mapping to :code:`True`:
|
110 |
+
|
111 |
+
- :code:`True`
|
112 |
+
- :code:`"true"` / :code:`"t"`
|
113 |
+
- :code:`"yes"` / :code:`"y"`
|
114 |
+
- :code:`"on"`
|
115 |
+
- :code:`"1"`
|
116 |
+
- :code:`1`
|
117 |
+
|
118 |
+
Values mapping to :code:`False`:
|
119 |
+
|
120 |
+
- :code:`False`
|
121 |
+
- :code:`"false"` / :code:`"f"`
|
122 |
+
- :code:`"no"` / :code:`"n"`
|
123 |
+
- :code:`"off"`
|
124 |
+
- :code:`"0"`
|
125 |
+
- :code:`0`
|
126 |
+
|
127 |
+
:raises ValueError: for any other value.
|
128 |
+
|
129 |
+
.. versionadded:: 21.3.0
|
130 |
+
"""
|
131 |
+
if isinstance(val, str):
|
132 |
+
val = val.lower()
|
133 |
+
truthy = {True, "true", "t", "yes", "y", "on", "1", 1}
|
134 |
+
falsy = {False, "false", "f", "no", "n", "off", "0", 0}
|
135 |
+
try:
|
136 |
+
if val in truthy:
|
137 |
+
return True
|
138 |
+
if val in falsy:
|
139 |
+
return False
|
140 |
+
except TypeError:
|
141 |
+
# Raised when "val" is not hashable (e.g., lists)
|
142 |
+
pass
|
143 |
+
msg = f"Cannot convert value to bool: {val}"
|
144 |
+
raise ValueError(msg)
|
llmeval-env/lib/python3.10/site-packages/attr/converters.pyi
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Callable, TypeVar, overload
|
2 |
+
|
3 |
+
from . import _ConverterType
|
4 |
+
|
5 |
+
_T = TypeVar("_T")
|
6 |
+
|
7 |
+
def pipe(*validators: _ConverterType) -> _ConverterType: ...
|
8 |
+
def optional(converter: _ConverterType) -> _ConverterType: ...
|
9 |
+
@overload
|
10 |
+
def default_if_none(default: _T) -> _ConverterType: ...
|
11 |
+
@overload
|
12 |
+
def default_if_none(*, factory: Callable[[], _T]) -> _ConverterType: ...
|
13 |
+
def to_bool(val: str) -> bool: ...
|
llmeval-env/lib/python3.10/site-packages/attr/exceptions.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
from __future__ import annotations
|
4 |
+
|
5 |
+
from typing import ClassVar
|
6 |
+
|
7 |
+
|
8 |
+
class FrozenError(AttributeError):
|
9 |
+
"""
|
10 |
+
A frozen/immutable instance or attribute have been attempted to be
|
11 |
+
modified.
|
12 |
+
|
13 |
+
It mirrors the behavior of ``namedtuples`` by using the same error message
|
14 |
+
and subclassing `AttributeError`.
|
15 |
+
|
16 |
+
.. versionadded:: 20.1.0
|
17 |
+
"""
|
18 |
+
|
19 |
+
msg = "can't set attribute"
|
20 |
+
args: ClassVar[tuple[str]] = [msg]
|
21 |
+
|
22 |
+
|
23 |
+
class FrozenInstanceError(FrozenError):
|
24 |
+
"""
|
25 |
+
A frozen instance has been attempted to be modified.
|
26 |
+
|
27 |
+
.. versionadded:: 16.1.0
|
28 |
+
"""
|
29 |
+
|
30 |
+
|
31 |
+
class FrozenAttributeError(FrozenError):
|
32 |
+
"""
|
33 |
+
A frozen attribute has been attempted to be modified.
|
34 |
+
|
35 |
+
.. versionadded:: 20.1.0
|
36 |
+
"""
|
37 |
+
|
38 |
+
|
39 |
+
class AttrsAttributeNotFoundError(ValueError):
|
40 |
+
"""
|
41 |
+
An *attrs* function couldn't find an attribute that the user asked for.
|
42 |
+
|
43 |
+
.. versionadded:: 16.2.0
|
44 |
+
"""
|
45 |
+
|
46 |
+
|
47 |
+
class NotAnAttrsClassError(ValueError):
|
48 |
+
"""
|
49 |
+
A non-*attrs* class has been passed into an *attrs* function.
|
50 |
+
|
51 |
+
.. versionadded:: 16.2.0
|
52 |
+
"""
|
53 |
+
|
54 |
+
|
55 |
+
class DefaultAlreadySetError(RuntimeError):
|
56 |
+
"""
|
57 |
+
A default has been set when defining the field and is attempted to be reset
|
58 |
+
using the decorator.
|
59 |
+
|
60 |
+
.. versionadded:: 17.1.0
|
61 |
+
"""
|
62 |
+
|
63 |
+
|
64 |
+
class UnannotatedAttributeError(RuntimeError):
|
65 |
+
"""
|
66 |
+
A class with ``auto_attribs=True`` has a field without a type annotation.
|
67 |
+
|
68 |
+
.. versionadded:: 17.3.0
|
69 |
+
"""
|
70 |
+
|
71 |
+
|
72 |
+
class PythonTooOldError(RuntimeError):
|
73 |
+
"""
|
74 |
+
It was attempted to use an *attrs* feature that requires a newer Python
|
75 |
+
version.
|
76 |
+
|
77 |
+
.. versionadded:: 18.2.0
|
78 |
+
"""
|
79 |
+
|
80 |
+
|
81 |
+
class NotCallableError(TypeError):
|
82 |
+
"""
|
83 |
+
A field requiring a callable has been set with a value that is not
|
84 |
+
callable.
|
85 |
+
|
86 |
+
.. versionadded:: 19.2.0
|
87 |
+
"""
|
88 |
+
|
89 |
+
def __init__(self, msg, value):
|
90 |
+
super(TypeError, self).__init__(msg, value)
|
91 |
+
self.msg = msg
|
92 |
+
self.value = value
|
93 |
+
|
94 |
+
def __str__(self):
|
95 |
+
return str(self.msg)
|
llmeval-env/lib/python3.10/site-packages/attr/exceptions.pyi
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any
|
2 |
+
|
3 |
+
class FrozenError(AttributeError):
|
4 |
+
msg: str = ...
|
5 |
+
|
6 |
+
class FrozenInstanceError(FrozenError): ...
|
7 |
+
class FrozenAttributeError(FrozenError): ...
|
8 |
+
class AttrsAttributeNotFoundError(ValueError): ...
|
9 |
+
class NotAnAttrsClassError(ValueError): ...
|
10 |
+
class DefaultAlreadySetError(RuntimeError): ...
|
11 |
+
class UnannotatedAttributeError(RuntimeError): ...
|
12 |
+
class PythonTooOldError(RuntimeError): ...
|
13 |
+
|
14 |
+
class NotCallableError(TypeError):
|
15 |
+
msg: str = ...
|
16 |
+
value: Any = ...
|
17 |
+
def __init__(self, msg: str, value: Any) -> None: ...
|
llmeval-env/lib/python3.10/site-packages/attr/filters.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
"""
|
4 |
+
Commonly useful filters for `attr.asdict`.
|
5 |
+
"""
|
6 |
+
|
7 |
+
from ._make import Attribute
|
8 |
+
|
9 |
+
|
10 |
+
def _split_what(what):
|
11 |
+
"""
|
12 |
+
Returns a tuple of `frozenset`s of classes and attributes.
|
13 |
+
"""
|
14 |
+
return (
|
15 |
+
frozenset(cls for cls in what if isinstance(cls, type)),
|
16 |
+
frozenset(cls for cls in what if isinstance(cls, str)),
|
17 |
+
frozenset(cls for cls in what if isinstance(cls, Attribute)),
|
18 |
+
)
|
19 |
+
|
20 |
+
|
21 |
+
def include(*what):
|
22 |
+
"""
|
23 |
+
Include *what*.
|
24 |
+
|
25 |
+
:param what: What to include.
|
26 |
+
:type what: `list` of classes `type`, field names `str` or
|
27 |
+
`attrs.Attribute`\\ s
|
28 |
+
|
29 |
+
:rtype: `callable`
|
30 |
+
|
31 |
+
.. versionchanged:: 23.1.0 Accept strings with field names.
|
32 |
+
"""
|
33 |
+
cls, names, attrs = _split_what(what)
|
34 |
+
|
35 |
+
def include_(attribute, value):
|
36 |
+
return (
|
37 |
+
value.__class__ in cls
|
38 |
+
or attribute.name in names
|
39 |
+
or attribute in attrs
|
40 |
+
)
|
41 |
+
|
42 |
+
return include_
|
43 |
+
|
44 |
+
|
45 |
+
def exclude(*what):
|
46 |
+
"""
|
47 |
+
Exclude *what*.
|
48 |
+
|
49 |
+
:param what: What to exclude.
|
50 |
+
:type what: `list` of classes `type`, field names `str` or
|
51 |
+
`attrs.Attribute`\\ s.
|
52 |
+
|
53 |
+
:rtype: `callable`
|
54 |
+
|
55 |
+
.. versionchanged:: 23.3.0 Accept field name string as input argument
|
56 |
+
"""
|
57 |
+
cls, names, attrs = _split_what(what)
|
58 |
+
|
59 |
+
def exclude_(attribute, value):
|
60 |
+
return not (
|
61 |
+
value.__class__ in cls
|
62 |
+
or attribute.name in names
|
63 |
+
or attribute in attrs
|
64 |
+
)
|
65 |
+
|
66 |
+
return exclude_
|
llmeval-env/lib/python3.10/site-packages/attr/filters.pyi
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Union
|
2 |
+
|
3 |
+
from . import Attribute, _FilterType
|
4 |
+
|
5 |
+
def include(*what: Union[type, str, Attribute[Any]]) -> _FilterType[Any]: ...
|
6 |
+
def exclude(*what: Union[type, str, Attribute[Any]]) -> _FilterType[Any]: ...
|
llmeval-env/lib/python3.10/site-packages/attr/py.typed
ADDED
File without changes
|
llmeval-env/lib/python3.10/site-packages/attr/setters.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
"""
|
4 |
+
Commonly used hooks for on_setattr.
|
5 |
+
"""
|
6 |
+
|
7 |
+
|
8 |
+
from . import _config
|
9 |
+
from .exceptions import FrozenAttributeError
|
10 |
+
|
11 |
+
|
12 |
+
def pipe(*setters):
|
13 |
+
"""
|
14 |
+
Run all *setters* and return the return value of the last one.
|
15 |
+
|
16 |
+
.. versionadded:: 20.1.0
|
17 |
+
"""
|
18 |
+
|
19 |
+
def wrapped_pipe(instance, attrib, new_value):
|
20 |
+
rv = new_value
|
21 |
+
|
22 |
+
for setter in setters:
|
23 |
+
rv = setter(instance, attrib, rv)
|
24 |
+
|
25 |
+
return rv
|
26 |
+
|
27 |
+
return wrapped_pipe
|
28 |
+
|
29 |
+
|
30 |
+
def frozen(_, __, ___):
|
31 |
+
"""
|
32 |
+
Prevent an attribute to be modified.
|
33 |
+
|
34 |
+
.. versionadded:: 20.1.0
|
35 |
+
"""
|
36 |
+
raise FrozenAttributeError()
|
37 |
+
|
38 |
+
|
39 |
+
def validate(instance, attrib, new_value):
|
40 |
+
"""
|
41 |
+
Run *attrib*'s validator on *new_value* if it has one.
|
42 |
+
|
43 |
+
.. versionadded:: 20.1.0
|
44 |
+
"""
|
45 |
+
if _config._run_validators is False:
|
46 |
+
return new_value
|
47 |
+
|
48 |
+
v = attrib.validator
|
49 |
+
if not v:
|
50 |
+
return new_value
|
51 |
+
|
52 |
+
v(instance, attrib, new_value)
|
53 |
+
|
54 |
+
return new_value
|
55 |
+
|
56 |
+
|
57 |
+
def convert(instance, attrib, new_value):
|
58 |
+
"""
|
59 |
+
Run *attrib*'s converter -- if it has one -- on *new_value* and return the
|
60 |
+
result.
|
61 |
+
|
62 |
+
.. versionadded:: 20.1.0
|
63 |
+
"""
|
64 |
+
c = attrib.converter
|
65 |
+
if c:
|
66 |
+
return c(new_value)
|
67 |
+
|
68 |
+
return new_value
|
69 |
+
|
70 |
+
|
71 |
+
# Sentinel for disabling class-wide *on_setattr* hooks for certain attributes.
|
72 |
+
# autodata stopped working, so the docstring is inlined in the API docs.
|
73 |
+
NO_OP = object()
|
llmeval-env/lib/python3.10/site-packages/attr/setters.pyi
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, NewType, NoReturn, TypeVar
|
2 |
+
|
3 |
+
from . import Attribute, _OnSetAttrType
|
4 |
+
|
5 |
+
_T = TypeVar("_T")
|
6 |
+
|
7 |
+
def frozen(
|
8 |
+
instance: Any, attribute: Attribute[Any], new_value: Any
|
9 |
+
) -> NoReturn: ...
|
10 |
+
def pipe(*setters: _OnSetAttrType) -> _OnSetAttrType: ...
|
11 |
+
def validate(instance: Any, attribute: Attribute[_T], new_value: _T) -> _T: ...
|
12 |
+
|
13 |
+
# convert is allowed to return Any, because they can be chained using pipe.
|
14 |
+
def convert(
|
15 |
+
instance: Any, attribute: Attribute[Any], new_value: Any
|
16 |
+
) -> Any: ...
|
17 |
+
|
18 |
+
_NoOpType = NewType("_NoOpType", object)
|
19 |
+
NO_OP: _NoOpType
|
llmeval-env/lib/python3.10/site-packages/attr/validators.py
ADDED
@@ -0,0 +1,681 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
"""
|
4 |
+
Commonly useful validators.
|
5 |
+
"""
|
6 |
+
|
7 |
+
|
8 |
+
import operator
|
9 |
+
import re
|
10 |
+
|
11 |
+
from contextlib import contextmanager
|
12 |
+
from re import Pattern
|
13 |
+
|
14 |
+
from ._config import get_run_validators, set_run_validators
|
15 |
+
from ._make import _AndValidator, and_, attrib, attrs
|
16 |
+
from .converters import default_if_none
|
17 |
+
from .exceptions import NotCallableError
|
18 |
+
|
19 |
+
|
20 |
+
__all__ = [
|
21 |
+
"and_",
|
22 |
+
"deep_iterable",
|
23 |
+
"deep_mapping",
|
24 |
+
"disabled",
|
25 |
+
"ge",
|
26 |
+
"get_disabled",
|
27 |
+
"gt",
|
28 |
+
"in_",
|
29 |
+
"instance_of",
|
30 |
+
"is_callable",
|
31 |
+
"le",
|
32 |
+
"lt",
|
33 |
+
"matches_re",
|
34 |
+
"max_len",
|
35 |
+
"min_len",
|
36 |
+
"not_",
|
37 |
+
"optional",
|
38 |
+
"provides",
|
39 |
+
"set_disabled",
|
40 |
+
]
|
41 |
+
|
42 |
+
|
43 |
+
def set_disabled(disabled):
|
44 |
+
"""
|
45 |
+
Globally disable or enable running validators.
|
46 |
+
|
47 |
+
By default, they are run.
|
48 |
+
|
49 |
+
:param disabled: If ``True``, disable running all validators.
|
50 |
+
:type disabled: bool
|
51 |
+
|
52 |
+
.. warning::
|
53 |
+
|
54 |
+
This function is not thread-safe!
|
55 |
+
|
56 |
+
.. versionadded:: 21.3.0
|
57 |
+
"""
|
58 |
+
set_run_validators(not disabled)
|
59 |
+
|
60 |
+
|
61 |
+
def get_disabled():
|
62 |
+
"""
|
63 |
+
Return a bool indicating whether validators are currently disabled or not.
|
64 |
+
|
65 |
+
:return: ``True`` if validators are currently disabled.
|
66 |
+
:rtype: bool
|
67 |
+
|
68 |
+
.. versionadded:: 21.3.0
|
69 |
+
"""
|
70 |
+
return not get_run_validators()
|
71 |
+
|
72 |
+
|
73 |
+
@contextmanager
|
74 |
+
def disabled():
|
75 |
+
"""
|
76 |
+
Context manager that disables running validators within its context.
|
77 |
+
|
78 |
+
.. warning::
|
79 |
+
|
80 |
+
This context manager is not thread-safe!
|
81 |
+
|
82 |
+
.. versionadded:: 21.3.0
|
83 |
+
"""
|
84 |
+
set_run_validators(False)
|
85 |
+
try:
|
86 |
+
yield
|
87 |
+
finally:
|
88 |
+
set_run_validators(True)
|
89 |
+
|
90 |
+
|
91 |
+
@attrs(repr=False, slots=True, hash=True)
|
92 |
+
class _InstanceOfValidator:
|
93 |
+
type = attrib()
|
94 |
+
|
95 |
+
def __call__(self, inst, attr, value):
|
96 |
+
"""
|
97 |
+
We use a callable class to be able to change the ``__repr__``.
|
98 |
+
"""
|
99 |
+
if not isinstance(value, self.type):
|
100 |
+
msg = "'{name}' must be {type!r} (got {value!r} that is a {actual!r}).".format(
|
101 |
+
name=attr.name,
|
102 |
+
type=self.type,
|
103 |
+
actual=value.__class__,
|
104 |
+
value=value,
|
105 |
+
)
|
106 |
+
raise TypeError(
|
107 |
+
msg,
|
108 |
+
attr,
|
109 |
+
self.type,
|
110 |
+
value,
|
111 |
+
)
|
112 |
+
|
113 |
+
def __repr__(self):
|
114 |
+
return f"<instance_of validator for type {self.type!r}>"
|
115 |
+
|
116 |
+
|
117 |
+
def instance_of(type):
|
118 |
+
"""
|
119 |
+
A validator that raises a `TypeError` if the initializer is called
|
120 |
+
with a wrong type for this particular attribute (checks are performed using
|
121 |
+
`isinstance` therefore it's also valid to pass a tuple of types).
|
122 |
+
|
123 |
+
:param type: The type to check for.
|
124 |
+
:type type: type or tuple of type
|
125 |
+
|
126 |
+
:raises TypeError: With a human readable error message, the attribute
|
127 |
+
(of type `attrs.Attribute`), the expected type, and the value it
|
128 |
+
got.
|
129 |
+
"""
|
130 |
+
return _InstanceOfValidator(type)
|
131 |
+
|
132 |
+
|
133 |
+
@attrs(repr=False, frozen=True, slots=True)
|
134 |
+
class _MatchesReValidator:
|
135 |
+
pattern = attrib()
|
136 |
+
match_func = attrib()
|
137 |
+
|
138 |
+
def __call__(self, inst, attr, value):
|
139 |
+
"""
|
140 |
+
We use a callable class to be able to change the ``__repr__``.
|
141 |
+
"""
|
142 |
+
if not self.match_func(value):
|
143 |
+
msg = "'{name}' must match regex {pattern!r} ({value!r} doesn't)".format(
|
144 |
+
name=attr.name, pattern=self.pattern.pattern, value=value
|
145 |
+
)
|
146 |
+
raise ValueError(
|
147 |
+
msg,
|
148 |
+
attr,
|
149 |
+
self.pattern,
|
150 |
+
value,
|
151 |
+
)
|
152 |
+
|
153 |
+
def __repr__(self):
|
154 |
+
return f"<matches_re validator for pattern {self.pattern!r}>"
|
155 |
+
|
156 |
+
|
157 |
+
def matches_re(regex, flags=0, func=None):
|
158 |
+
r"""
|
159 |
+
A validator that raises `ValueError` if the initializer is called
|
160 |
+
with a string that doesn't match *regex*.
|
161 |
+
|
162 |
+
:param regex: a regex string or precompiled pattern to match against
|
163 |
+
:param int flags: flags that will be passed to the underlying re function
|
164 |
+
(default 0)
|
165 |
+
:param callable func: which underlying `re` function to call. Valid options
|
166 |
+
are `re.fullmatch`, `re.search`, and `re.match`; the default ``None``
|
167 |
+
means `re.fullmatch`. For performance reasons, the pattern is always
|
168 |
+
precompiled using `re.compile`.
|
169 |
+
|
170 |
+
.. versionadded:: 19.2.0
|
171 |
+
.. versionchanged:: 21.3.0 *regex* can be a pre-compiled pattern.
|
172 |
+
"""
|
173 |
+
valid_funcs = (re.fullmatch, None, re.search, re.match)
|
174 |
+
if func not in valid_funcs:
|
175 |
+
msg = "'func' must be one of {}.".format(
|
176 |
+
", ".join(
|
177 |
+
sorted(e and e.__name__ or "None" for e in set(valid_funcs))
|
178 |
+
)
|
179 |
+
)
|
180 |
+
raise ValueError(msg)
|
181 |
+
|
182 |
+
if isinstance(regex, Pattern):
|
183 |
+
if flags:
|
184 |
+
msg = "'flags' can only be used with a string pattern; pass flags to re.compile() instead"
|
185 |
+
raise TypeError(msg)
|
186 |
+
pattern = regex
|
187 |
+
else:
|
188 |
+
pattern = re.compile(regex, flags)
|
189 |
+
|
190 |
+
if func is re.match:
|
191 |
+
match_func = pattern.match
|
192 |
+
elif func is re.search:
|
193 |
+
match_func = pattern.search
|
194 |
+
else:
|
195 |
+
match_func = pattern.fullmatch
|
196 |
+
|
197 |
+
return _MatchesReValidator(pattern, match_func)
|
198 |
+
|
199 |
+
|
200 |
+
@attrs(repr=False, slots=True, hash=True)
|
201 |
+
class _ProvidesValidator:
|
202 |
+
interface = attrib()
|
203 |
+
|
204 |
+
def __call__(self, inst, attr, value):
|
205 |
+
"""
|
206 |
+
We use a callable class to be able to change the ``__repr__``.
|
207 |
+
"""
|
208 |
+
if not self.interface.providedBy(value):
|
209 |
+
msg = "'{name}' must provide {interface!r} which {value!r} doesn't.".format(
|
210 |
+
name=attr.name, interface=self.interface, value=value
|
211 |
+
)
|
212 |
+
raise TypeError(
|
213 |
+
msg,
|
214 |
+
attr,
|
215 |
+
self.interface,
|
216 |
+
value,
|
217 |
+
)
|
218 |
+
|
219 |
+
def __repr__(self):
|
220 |
+
return f"<provides validator for interface {self.interface!r}>"
|
221 |
+
|
222 |
+
|
223 |
+
def provides(interface):
|
224 |
+
"""
|
225 |
+
A validator that raises a `TypeError` if the initializer is called
|
226 |
+
with an object that does not provide the requested *interface* (checks are
|
227 |
+
performed using ``interface.providedBy(value)`` (see `zope.interface
|
228 |
+
<https://zopeinterface.readthedocs.io/en/latest/>`_).
|
229 |
+
|
230 |
+
:param interface: The interface to check for.
|
231 |
+
:type interface: ``zope.interface.Interface``
|
232 |
+
|
233 |
+
:raises TypeError: With a human readable error message, the attribute
|
234 |
+
(of type `attrs.Attribute`), the expected interface, and the
|
235 |
+
value it got.
|
236 |
+
|
237 |
+
.. deprecated:: 23.1.0
|
238 |
+
"""
|
239 |
+
import warnings
|
240 |
+
|
241 |
+
warnings.warn(
|
242 |
+
"attrs's zope-interface support is deprecated and will be removed in, "
|
243 |
+
"or after, April 2024.",
|
244 |
+
DeprecationWarning,
|
245 |
+
stacklevel=2,
|
246 |
+
)
|
247 |
+
return _ProvidesValidator(interface)
|
248 |
+
|
249 |
+
|
250 |
+
@attrs(repr=False, slots=True, hash=True)
|
251 |
+
class _OptionalValidator:
|
252 |
+
validator = attrib()
|
253 |
+
|
254 |
+
def __call__(self, inst, attr, value):
|
255 |
+
if value is None:
|
256 |
+
return
|
257 |
+
|
258 |
+
self.validator(inst, attr, value)
|
259 |
+
|
260 |
+
def __repr__(self):
|
261 |
+
return f"<optional validator for {self.validator!r} or None>"
|
262 |
+
|
263 |
+
|
264 |
+
def optional(validator):
|
265 |
+
"""
|
266 |
+
A validator that makes an attribute optional. An optional attribute is one
|
267 |
+
which can be set to ``None`` in addition to satisfying the requirements of
|
268 |
+
the sub-validator.
|
269 |
+
|
270 |
+
:param Callable | tuple[Callable] | list[Callable] validator: A validator
|
271 |
+
(or validators) that is used for non-``None`` values.
|
272 |
+
|
273 |
+
.. versionadded:: 15.1.0
|
274 |
+
.. versionchanged:: 17.1.0 *validator* can be a list of validators.
|
275 |
+
.. versionchanged:: 23.1.0 *validator* can also be a tuple of validators.
|
276 |
+
"""
|
277 |
+
if isinstance(validator, (list, tuple)):
|
278 |
+
return _OptionalValidator(_AndValidator(validator))
|
279 |
+
|
280 |
+
return _OptionalValidator(validator)
|
281 |
+
|
282 |
+
|
283 |
+
@attrs(repr=False, slots=True, hash=True)
|
284 |
+
class _InValidator:
|
285 |
+
options = attrib()
|
286 |
+
|
287 |
+
def __call__(self, inst, attr, value):
|
288 |
+
try:
|
289 |
+
in_options = value in self.options
|
290 |
+
except TypeError: # e.g. `1 in "abc"`
|
291 |
+
in_options = False
|
292 |
+
|
293 |
+
if not in_options:
|
294 |
+
msg = f"'{attr.name}' must be in {self.options!r} (got {value!r})"
|
295 |
+
raise ValueError(
|
296 |
+
msg,
|
297 |
+
attr,
|
298 |
+
self.options,
|
299 |
+
value,
|
300 |
+
)
|
301 |
+
|
302 |
+
def __repr__(self):
|
303 |
+
return f"<in_ validator with options {self.options!r}>"
|
304 |
+
|
305 |
+
|
306 |
+
def in_(options):
|
307 |
+
"""
|
308 |
+
A validator that raises a `ValueError` if the initializer is called
|
309 |
+
with a value that does not belong in the options provided. The check is
|
310 |
+
performed using ``value in options``.
|
311 |
+
|
312 |
+
:param options: Allowed options.
|
313 |
+
:type options: list, tuple, `enum.Enum`, ...
|
314 |
+
|
315 |
+
:raises ValueError: With a human readable error message, the attribute (of
|
316 |
+
type `attrs.Attribute`), the expected options, and the value it
|
317 |
+
got.
|
318 |
+
|
319 |
+
.. versionadded:: 17.1.0
|
320 |
+
.. versionchanged:: 22.1.0
|
321 |
+
The ValueError was incomplete until now and only contained the human
|
322 |
+
readable error message. Now it contains all the information that has
|
323 |
+
been promised since 17.1.0.
|
324 |
+
"""
|
325 |
+
return _InValidator(options)
|
326 |
+
|
327 |
+
|
328 |
+
@attrs(repr=False, slots=False, hash=True)
|
329 |
+
class _IsCallableValidator:
|
330 |
+
def __call__(self, inst, attr, value):
|
331 |
+
"""
|
332 |
+
We use a callable class to be able to change the ``__repr__``.
|
333 |
+
"""
|
334 |
+
if not callable(value):
|
335 |
+
message = (
|
336 |
+
"'{name}' must be callable "
|
337 |
+
"(got {value!r} that is a {actual!r})."
|
338 |
+
)
|
339 |
+
raise NotCallableError(
|
340 |
+
msg=message.format(
|
341 |
+
name=attr.name, value=value, actual=value.__class__
|
342 |
+
),
|
343 |
+
value=value,
|
344 |
+
)
|
345 |
+
|
346 |
+
def __repr__(self):
|
347 |
+
return "<is_callable validator>"
|
348 |
+
|
349 |
+
|
350 |
+
def is_callable():
|
351 |
+
"""
|
352 |
+
A validator that raises a `attrs.exceptions.NotCallableError` if the
|
353 |
+
initializer is called with a value for this particular attribute
|
354 |
+
that is not callable.
|
355 |
+
|
356 |
+
.. versionadded:: 19.1.0
|
357 |
+
|
358 |
+
:raises attrs.exceptions.NotCallableError: With a human readable error
|
359 |
+
message containing the attribute (`attrs.Attribute`) name,
|
360 |
+
and the value it got.
|
361 |
+
"""
|
362 |
+
return _IsCallableValidator()
|
363 |
+
|
364 |
+
|
365 |
+
@attrs(repr=False, slots=True, hash=True)
|
366 |
+
class _DeepIterable:
|
367 |
+
member_validator = attrib(validator=is_callable())
|
368 |
+
iterable_validator = attrib(
|
369 |
+
default=None, validator=optional(is_callable())
|
370 |
+
)
|
371 |
+
|
372 |
+
def __call__(self, inst, attr, value):
|
373 |
+
"""
|
374 |
+
We use a callable class to be able to change the ``__repr__``.
|
375 |
+
"""
|
376 |
+
if self.iterable_validator is not None:
|
377 |
+
self.iterable_validator(inst, attr, value)
|
378 |
+
|
379 |
+
for member in value:
|
380 |
+
self.member_validator(inst, attr, member)
|
381 |
+
|
382 |
+
def __repr__(self):
|
383 |
+
iterable_identifier = (
|
384 |
+
""
|
385 |
+
if self.iterable_validator is None
|
386 |
+
else f" {self.iterable_validator!r}"
|
387 |
+
)
|
388 |
+
return (
|
389 |
+
f"<deep_iterable validator for{iterable_identifier}"
|
390 |
+
f" iterables of {self.member_validator!r}>"
|
391 |
+
)
|
392 |
+
|
393 |
+
|
394 |
+
def deep_iterable(member_validator, iterable_validator=None):
|
395 |
+
"""
|
396 |
+
A validator that performs deep validation of an iterable.
|
397 |
+
|
398 |
+
:param member_validator: Validator(s) to apply to iterable members
|
399 |
+
:param iterable_validator: Validator to apply to iterable itself
|
400 |
+
(optional)
|
401 |
+
|
402 |
+
.. versionadded:: 19.1.0
|
403 |
+
|
404 |
+
:raises TypeError: if any sub-validators fail
|
405 |
+
"""
|
406 |
+
if isinstance(member_validator, (list, tuple)):
|
407 |
+
member_validator = and_(*member_validator)
|
408 |
+
return _DeepIterable(member_validator, iterable_validator)
|
409 |
+
|
410 |
+
|
411 |
+
@attrs(repr=False, slots=True, hash=True)
|
412 |
+
class _DeepMapping:
|
413 |
+
key_validator = attrib(validator=is_callable())
|
414 |
+
value_validator = attrib(validator=is_callable())
|
415 |
+
mapping_validator = attrib(default=None, validator=optional(is_callable()))
|
416 |
+
|
417 |
+
def __call__(self, inst, attr, value):
|
418 |
+
"""
|
419 |
+
We use a callable class to be able to change the ``__repr__``.
|
420 |
+
"""
|
421 |
+
if self.mapping_validator is not None:
|
422 |
+
self.mapping_validator(inst, attr, value)
|
423 |
+
|
424 |
+
for key in value:
|
425 |
+
self.key_validator(inst, attr, key)
|
426 |
+
self.value_validator(inst, attr, value[key])
|
427 |
+
|
428 |
+
def __repr__(self):
|
429 |
+
return (
|
430 |
+
"<deep_mapping validator for objects mapping {key!r} to {value!r}>"
|
431 |
+
).format(key=self.key_validator, value=self.value_validator)
|
432 |
+
|
433 |
+
|
434 |
+
def deep_mapping(key_validator, value_validator, mapping_validator=None):
|
435 |
+
"""
|
436 |
+
A validator that performs deep validation of a dictionary.
|
437 |
+
|
438 |
+
:param key_validator: Validator to apply to dictionary keys
|
439 |
+
:param value_validator: Validator to apply to dictionary values
|
440 |
+
:param mapping_validator: Validator to apply to top-level mapping
|
441 |
+
attribute (optional)
|
442 |
+
|
443 |
+
.. versionadded:: 19.1.0
|
444 |
+
|
445 |
+
:raises TypeError: if any sub-validators fail
|
446 |
+
"""
|
447 |
+
return _DeepMapping(key_validator, value_validator, mapping_validator)
|
448 |
+
|
449 |
+
|
450 |
+
@attrs(repr=False, frozen=True, slots=True)
|
451 |
+
class _NumberValidator:
|
452 |
+
bound = attrib()
|
453 |
+
compare_op = attrib()
|
454 |
+
compare_func = attrib()
|
455 |
+
|
456 |
+
def __call__(self, inst, attr, value):
|
457 |
+
"""
|
458 |
+
We use a callable class to be able to change the ``__repr__``.
|
459 |
+
"""
|
460 |
+
if not self.compare_func(value, self.bound):
|
461 |
+
msg = f"'{attr.name}' must be {self.compare_op} {self.bound}: {value}"
|
462 |
+
raise ValueError(msg)
|
463 |
+
|
464 |
+
def __repr__(self):
|
465 |
+
return f"<Validator for x {self.compare_op} {self.bound}>"
|
466 |
+
|
467 |
+
|
468 |
+
def lt(val):
|
469 |
+
"""
|
470 |
+
A validator that raises `ValueError` if the initializer is called
|
471 |
+
with a number larger or equal to *val*.
|
472 |
+
|
473 |
+
:param val: Exclusive upper bound for values
|
474 |
+
|
475 |
+
.. versionadded:: 21.3.0
|
476 |
+
"""
|
477 |
+
return _NumberValidator(val, "<", operator.lt)
|
478 |
+
|
479 |
+
|
480 |
+
def le(val):
|
481 |
+
"""
|
482 |
+
A validator that raises `ValueError` if the initializer is called
|
483 |
+
with a number greater than *val*.
|
484 |
+
|
485 |
+
:param val: Inclusive upper bound for values
|
486 |
+
|
487 |
+
.. versionadded:: 21.3.0
|
488 |
+
"""
|
489 |
+
return _NumberValidator(val, "<=", operator.le)
|
490 |
+
|
491 |
+
|
492 |
+
def ge(val):
|
493 |
+
"""
|
494 |
+
A validator that raises `ValueError` if the initializer is called
|
495 |
+
with a number smaller than *val*.
|
496 |
+
|
497 |
+
:param val: Inclusive lower bound for values
|
498 |
+
|
499 |
+
.. versionadded:: 21.3.0
|
500 |
+
"""
|
501 |
+
return _NumberValidator(val, ">=", operator.ge)
|
502 |
+
|
503 |
+
|
504 |
+
def gt(val):
|
505 |
+
"""
|
506 |
+
A validator that raises `ValueError` if the initializer is called
|
507 |
+
with a number smaller or equal to *val*.
|
508 |
+
|
509 |
+
:param val: Exclusive lower bound for values
|
510 |
+
|
511 |
+
.. versionadded:: 21.3.0
|
512 |
+
"""
|
513 |
+
return _NumberValidator(val, ">", operator.gt)
|
514 |
+
|
515 |
+
|
516 |
+
@attrs(repr=False, frozen=True, slots=True)
|
517 |
+
class _MaxLengthValidator:
|
518 |
+
max_length = attrib()
|
519 |
+
|
520 |
+
def __call__(self, inst, attr, value):
|
521 |
+
"""
|
522 |
+
We use a callable class to be able to change the ``__repr__``.
|
523 |
+
"""
|
524 |
+
if len(value) > self.max_length:
|
525 |
+
msg = f"Length of '{attr.name}' must be <= {self.max_length}: {len(value)}"
|
526 |
+
raise ValueError(msg)
|
527 |
+
|
528 |
+
def __repr__(self):
|
529 |
+
return f"<max_len validator for {self.max_length}>"
|
530 |
+
|
531 |
+
|
532 |
+
def max_len(length):
|
533 |
+
"""
|
534 |
+
A validator that raises `ValueError` if the initializer is called
|
535 |
+
with a string or iterable that is longer than *length*.
|
536 |
+
|
537 |
+
:param int length: Maximum length of the string or iterable
|
538 |
+
|
539 |
+
.. versionadded:: 21.3.0
|
540 |
+
"""
|
541 |
+
return _MaxLengthValidator(length)
|
542 |
+
|
543 |
+
|
544 |
+
@attrs(repr=False, frozen=True, slots=True)
|
545 |
+
class _MinLengthValidator:
|
546 |
+
min_length = attrib()
|
547 |
+
|
548 |
+
def __call__(self, inst, attr, value):
|
549 |
+
"""
|
550 |
+
We use a callable class to be able to change the ``__repr__``.
|
551 |
+
"""
|
552 |
+
if len(value) < self.min_length:
|
553 |
+
msg = f"Length of '{attr.name}' must be >= {self.min_length}: {len(value)}"
|
554 |
+
raise ValueError(msg)
|
555 |
+
|
556 |
+
def __repr__(self):
|
557 |
+
return f"<min_len validator for {self.min_length}>"
|
558 |
+
|
559 |
+
|
560 |
+
def min_len(length):
|
561 |
+
"""
|
562 |
+
A validator that raises `ValueError` if the initializer is called
|
563 |
+
with a string or iterable that is shorter than *length*.
|
564 |
+
|
565 |
+
:param int length: Minimum length of the string or iterable
|
566 |
+
|
567 |
+
.. versionadded:: 22.1.0
|
568 |
+
"""
|
569 |
+
return _MinLengthValidator(length)
|
570 |
+
|
571 |
+
|
572 |
+
@attrs(repr=False, slots=True, hash=True)
|
573 |
+
class _SubclassOfValidator:
|
574 |
+
type = attrib()
|
575 |
+
|
576 |
+
def __call__(self, inst, attr, value):
|
577 |
+
"""
|
578 |
+
We use a callable class to be able to change the ``__repr__``.
|
579 |
+
"""
|
580 |
+
if not issubclass(value, self.type):
|
581 |
+
msg = f"'{attr.name}' must be a subclass of {self.type!r} (got {value!r})."
|
582 |
+
raise TypeError(
|
583 |
+
msg,
|
584 |
+
attr,
|
585 |
+
self.type,
|
586 |
+
value,
|
587 |
+
)
|
588 |
+
|
589 |
+
def __repr__(self):
|
590 |
+
return f"<subclass_of validator for type {self.type!r}>"
|
591 |
+
|
592 |
+
|
593 |
+
def _subclass_of(type):
|
594 |
+
"""
|
595 |
+
A validator that raises a `TypeError` if the initializer is called
|
596 |
+
with a wrong type for this particular attribute (checks are performed using
|
597 |
+
`issubclass` therefore it's also valid to pass a tuple of types).
|
598 |
+
|
599 |
+
:param type: The type to check for.
|
600 |
+
:type type: type or tuple of types
|
601 |
+
|
602 |
+
:raises TypeError: With a human readable error message, the attribute
|
603 |
+
(of type `attrs.Attribute`), the expected type, and the value it
|
604 |
+
got.
|
605 |
+
"""
|
606 |
+
return _SubclassOfValidator(type)
|
607 |
+
|
608 |
+
|
609 |
+
@attrs(repr=False, slots=True, hash=True)
|
610 |
+
class _NotValidator:
|
611 |
+
validator = attrib()
|
612 |
+
msg = attrib(
|
613 |
+
converter=default_if_none(
|
614 |
+
"not_ validator child '{validator!r}' "
|
615 |
+
"did not raise a captured error"
|
616 |
+
)
|
617 |
+
)
|
618 |
+
exc_types = attrib(
|
619 |
+
validator=deep_iterable(
|
620 |
+
member_validator=_subclass_of(Exception),
|
621 |
+
iterable_validator=instance_of(tuple),
|
622 |
+
),
|
623 |
+
)
|
624 |
+
|
625 |
+
def __call__(self, inst, attr, value):
|
626 |
+
try:
|
627 |
+
self.validator(inst, attr, value)
|
628 |
+
except self.exc_types:
|
629 |
+
pass # suppress error to invert validity
|
630 |
+
else:
|
631 |
+
raise ValueError(
|
632 |
+
self.msg.format(
|
633 |
+
validator=self.validator,
|
634 |
+
exc_types=self.exc_types,
|
635 |
+
),
|
636 |
+
attr,
|
637 |
+
self.validator,
|
638 |
+
value,
|
639 |
+
self.exc_types,
|
640 |
+
)
|
641 |
+
|
642 |
+
def __repr__(self):
|
643 |
+
return (
|
644 |
+
"<not_ validator wrapping {what!r}, capturing {exc_types!r}>"
|
645 |
+
).format(
|
646 |
+
what=self.validator,
|
647 |
+
exc_types=self.exc_types,
|
648 |
+
)
|
649 |
+
|
650 |
+
|
651 |
+
def not_(validator, *, msg=None, exc_types=(ValueError, TypeError)):
|
652 |
+
"""
|
653 |
+
A validator that wraps and logically 'inverts' the validator passed to it.
|
654 |
+
It will raise a `ValueError` if the provided validator *doesn't* raise a
|
655 |
+
`ValueError` or `TypeError` (by default), and will suppress the exception
|
656 |
+
if the provided validator *does*.
|
657 |
+
|
658 |
+
Intended to be used with existing validators to compose logic without
|
659 |
+
needing to create inverted variants, for example, ``not_(in_(...))``.
|
660 |
+
|
661 |
+
:param validator: A validator to be logically inverted.
|
662 |
+
:param msg: Message to raise if validator fails.
|
663 |
+
Formatted with keys ``exc_types`` and ``validator``.
|
664 |
+
:type msg: str
|
665 |
+
:param exc_types: Exception type(s) to capture.
|
666 |
+
Other types raised by child validators will not be intercepted and
|
667 |
+
pass through.
|
668 |
+
|
669 |
+
:raises ValueError: With a human readable error message,
|
670 |
+
the attribute (of type `attrs.Attribute`),
|
671 |
+
the validator that failed to raise an exception,
|
672 |
+
the value it got,
|
673 |
+
and the expected exception types.
|
674 |
+
|
675 |
+
.. versionadded:: 22.2.0
|
676 |
+
"""
|
677 |
+
try:
|
678 |
+
exc_types = tuple(exc_types)
|
679 |
+
except TypeError:
|
680 |
+
exc_types = (exc_types,)
|
681 |
+
return _NotValidator(validator, msg, exc_types)
|
llmeval-env/lib/python3.10/site-packages/attr/validators.pyi
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import (
|
2 |
+
Any,
|
3 |
+
AnyStr,
|
4 |
+
Callable,
|
5 |
+
Container,
|
6 |
+
ContextManager,
|
7 |
+
Iterable,
|
8 |
+
List,
|
9 |
+
Mapping,
|
10 |
+
Match,
|
11 |
+
Optional,
|
12 |
+
Pattern,
|
13 |
+
Tuple,
|
14 |
+
Type,
|
15 |
+
TypeVar,
|
16 |
+
Union,
|
17 |
+
overload,
|
18 |
+
)
|
19 |
+
|
20 |
+
from . import _ValidatorType
|
21 |
+
from . import _ValidatorArgType
|
22 |
+
|
23 |
+
_T = TypeVar("_T")
|
24 |
+
_T1 = TypeVar("_T1")
|
25 |
+
_T2 = TypeVar("_T2")
|
26 |
+
_T3 = TypeVar("_T3")
|
27 |
+
_I = TypeVar("_I", bound=Iterable)
|
28 |
+
_K = TypeVar("_K")
|
29 |
+
_V = TypeVar("_V")
|
30 |
+
_M = TypeVar("_M", bound=Mapping)
|
31 |
+
|
32 |
+
def set_disabled(run: bool) -> None: ...
|
33 |
+
def get_disabled() -> bool: ...
|
34 |
+
def disabled() -> ContextManager[None]: ...
|
35 |
+
|
36 |
+
# To be more precise on instance_of use some overloads.
|
37 |
+
# If there are more than 3 items in the tuple then we fall back to Any
|
38 |
+
@overload
|
39 |
+
def instance_of(type: Type[_T]) -> _ValidatorType[_T]: ...
|
40 |
+
@overload
|
41 |
+
def instance_of(type: Tuple[Type[_T]]) -> _ValidatorType[_T]: ...
|
42 |
+
@overload
|
43 |
+
def instance_of(
|
44 |
+
type: Tuple[Type[_T1], Type[_T2]]
|
45 |
+
) -> _ValidatorType[Union[_T1, _T2]]: ...
|
46 |
+
@overload
|
47 |
+
def instance_of(
|
48 |
+
type: Tuple[Type[_T1], Type[_T2], Type[_T3]]
|
49 |
+
) -> _ValidatorType[Union[_T1, _T2, _T3]]: ...
|
50 |
+
@overload
|
51 |
+
def instance_of(type: Tuple[type, ...]) -> _ValidatorType[Any]: ...
|
52 |
+
def provides(interface: Any) -> _ValidatorType[Any]: ...
|
53 |
+
def optional(
|
54 |
+
validator: Union[
|
55 |
+
_ValidatorType[_T], List[_ValidatorType[_T]], Tuple[_ValidatorType[_T]]
|
56 |
+
]
|
57 |
+
) -> _ValidatorType[Optional[_T]]: ...
|
58 |
+
def in_(options: Container[_T]) -> _ValidatorType[_T]: ...
|
59 |
+
def and_(*validators: _ValidatorType[_T]) -> _ValidatorType[_T]: ...
|
60 |
+
def matches_re(
|
61 |
+
regex: Union[Pattern[AnyStr], AnyStr],
|
62 |
+
flags: int = ...,
|
63 |
+
func: Optional[
|
64 |
+
Callable[[AnyStr, AnyStr, int], Optional[Match[AnyStr]]]
|
65 |
+
] = ...,
|
66 |
+
) -> _ValidatorType[AnyStr]: ...
|
67 |
+
def deep_iterable(
|
68 |
+
member_validator: _ValidatorArgType[_T],
|
69 |
+
iterable_validator: Optional[_ValidatorType[_I]] = ...,
|
70 |
+
) -> _ValidatorType[_I]: ...
|
71 |
+
def deep_mapping(
|
72 |
+
key_validator: _ValidatorType[_K],
|
73 |
+
value_validator: _ValidatorType[_V],
|
74 |
+
mapping_validator: Optional[_ValidatorType[_M]] = ...,
|
75 |
+
) -> _ValidatorType[_M]: ...
|
76 |
+
def is_callable() -> _ValidatorType[_T]: ...
|
77 |
+
def lt(val: _T) -> _ValidatorType[_T]: ...
|
78 |
+
def le(val: _T) -> _ValidatorType[_T]: ...
|
79 |
+
def ge(val: _T) -> _ValidatorType[_T]: ...
|
80 |
+
def gt(val: _T) -> _ValidatorType[_T]: ...
|
81 |
+
def max_len(length: int) -> _ValidatorType[_T]: ...
|
82 |
+
def min_len(length: int) -> _ValidatorType[_T]: ...
|
83 |
+
def not_(
|
84 |
+
validator: _ValidatorType[_T],
|
85 |
+
*,
|
86 |
+
msg: Optional[str] = None,
|
87 |
+
exc_types: Union[Type[Exception], Iterable[Type[Exception]]] = ...,
|
88 |
+
) -> _ValidatorType[_T]: ...
|
llmeval-env/lib/python3.10/site-packages/joblib-1.4.2.dist-info/INSTALLER
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pip
|
llmeval-env/lib/python3.10/site-packages/joblib-1.4.2.dist-info/LICENSE.txt
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
BSD 3-Clause License
|
2 |
+
|
3 |
+
Copyright (c) 2008-2021, The joblib developers.
|
4 |
+
All rights reserved.
|
5 |
+
|
6 |
+
Redistribution and use in source and binary forms, with or without
|
7 |
+
modification, are permitted provided that the following conditions are met:
|
8 |
+
|
9 |
+
* Redistributions of source code must retain the above copyright notice, this
|
10 |
+
list of conditions and the following disclaimer.
|
11 |
+
|
12 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
this list of conditions and the following disclaimer in the documentation
|
14 |
+
and/or other materials provided with the distribution.
|
15 |
+
|
16 |
+
* Neither the name of the copyright holder nor the names of its
|
17 |
+
contributors may be used to endorse or promote products derived from
|
18 |
+
this software without specific prior written permission.
|
19 |
+
|
20 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
24 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
llmeval-env/lib/python3.10/site-packages/joblib-1.4.2.dist-info/METADATA
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: joblib
|
3 |
+
Version: 1.4.2
|
4 |
+
Summary: Lightweight pipelining with Python functions
|
5 |
+
Author-email: Gael Varoquaux <[email protected]>
|
6 |
+
License: BSD 3-Clause
|
7 |
+
Project-URL: Homepage, https://joblib.readthedocs.io
|
8 |
+
Project-URL: Source, https://github.com/joblib/joblib
|
9 |
+
Platform: any
|
10 |
+
Classifier: Development Status :: 5 - Production/Stable
|
11 |
+
Classifier: Environment :: Console
|
12 |
+
Classifier: Intended Audience :: Developers
|
13 |
+
Classifier: Intended Audience :: Science/Research
|
14 |
+
Classifier: Intended Audience :: Education
|
15 |
+
Classifier: License :: OSI Approved :: BSD License
|
16 |
+
Classifier: Operating System :: OS Independent
|
17 |
+
Classifier: Programming Language :: Python :: 3
|
18 |
+
Classifier: Programming Language :: Python :: 3.8
|
19 |
+
Classifier: Programming Language :: Python :: 3.9
|
20 |
+
Classifier: Programming Language :: Python :: 3.10
|
21 |
+
Classifier: Programming Language :: Python :: 3.11
|
22 |
+
Classifier: Programming Language :: Python :: 3.12
|
23 |
+
Classifier: Topic :: Scientific/Engineering
|
24 |
+
Classifier: Topic :: Utilities
|
25 |
+
Classifier: Topic :: Software Development :: Libraries
|
26 |
+
Requires-Python: >=3.8
|
27 |
+
Description-Content-Type: text/x-rst
|
28 |
+
License-File: LICENSE.txt
|
29 |
+
|
30 |
+
|PyPi| |Azure| |ReadTheDocs| |Codecov|
|
31 |
+
|
32 |
+
.. |PyPi| image:: https://badge.fury.io/py/joblib.svg
|
33 |
+
:target: https://badge.fury.io/py/joblib
|
34 |
+
:alt: Joblib version
|
35 |
+
|
36 |
+
.. |Azure| image:: https://dev.azure.com/joblib/joblib/_apis/build/status/joblib.joblib?branchName=main
|
37 |
+
:target: https://dev.azure.com/joblib/joblib/_build?definitionId=3&_a=summary&branchFilter=40
|
38 |
+
:alt: Azure CI status
|
39 |
+
|
40 |
+
.. |ReadTheDocs| image:: https://readthedocs.org/projects/joblib/badge/?version=latest
|
41 |
+
:target: https://joblib.readthedocs.io/en/latest/?badge=latest
|
42 |
+
:alt: Documentation Status
|
43 |
+
|
44 |
+
.. |Codecov| image:: https://codecov.io/gh/joblib/joblib/branch/main/graph/badge.svg
|
45 |
+
:target: https://codecov.io/gh/joblib/joblib
|
46 |
+
:alt: Codecov coverage
|
47 |
+
|
48 |
+
|
49 |
+
The homepage of joblib with user documentation is located on:
|
50 |
+
|
51 |
+
https://joblib.readthedocs.io
|
52 |
+
|
53 |
+
Getting the latest code
|
54 |
+
=======================
|
55 |
+
|
56 |
+
To get the latest code using git, simply type::
|
57 |
+
|
58 |
+
git clone https://github.com/joblib/joblib.git
|
59 |
+
|
60 |
+
If you don't have git installed, you can download a zip
|
61 |
+
of the latest code: https://github.com/joblib/joblib/archive/refs/heads/main.zip
|
62 |
+
|
63 |
+
Installing
|
64 |
+
==========
|
65 |
+
|
66 |
+
You can use `pip` to install joblib::
|
67 |
+
|
68 |
+
pip install joblib
|
69 |
+
|
70 |
+
from any directory or::
|
71 |
+
|
72 |
+
python setup.py install
|
73 |
+
|
74 |
+
from the source directory.
|
75 |
+
|
76 |
+
Dependencies
|
77 |
+
============
|
78 |
+
|
79 |
+
- Joblib has no mandatory dependencies besides Python (supported versions are
|
80 |
+
3.8+).
|
81 |
+
- Joblib has an optional dependency on Numpy (at least version 1.6.1) for array
|
82 |
+
manipulation.
|
83 |
+
- Joblib includes its own vendored copy of
|
84 |
+
`loky <https://github.com/tomMoral/loky>`_ for process management.
|
85 |
+
- Joblib can efficiently dump and load numpy arrays but does not require numpy
|
86 |
+
to be installed.
|
87 |
+
- Joblib has an optional dependency on
|
88 |
+
`python-lz4 <https://pypi.python.org/pypi/lz4>`_ as a faster alternative to
|
89 |
+
zlib and gzip for compressed serialization.
|
90 |
+
- Joblib has an optional dependency on psutil to mitigate memory leaks in
|
91 |
+
parallel worker processes.
|
92 |
+
- Some examples require external dependencies such as pandas. See the
|
93 |
+
instructions in the `Building the docs`_ section for details.
|
94 |
+
|
95 |
+
Workflow to contribute
|
96 |
+
======================
|
97 |
+
|
98 |
+
To contribute to joblib, first create an account on `github
|
99 |
+
<https://github.com/>`_. Once this is done, fork the `joblib repository
|
100 |
+
<https://github.com/joblib/joblib>`_ to have your own repository,
|
101 |
+
clone it using 'git clone' on the computers where you want to work. Make
|
102 |
+
your changes in your clone, push them to your github account, test them
|
103 |
+
on several computers, and when you are happy with them, send a pull
|
104 |
+
request to the main repository.
|
105 |
+
|
106 |
+
Running the test suite
|
107 |
+
======================
|
108 |
+
|
109 |
+
To run the test suite, you need the pytest (version >= 3) and coverage modules.
|
110 |
+
Run the test suite using::
|
111 |
+
|
112 |
+
pytest joblib
|
113 |
+
|
114 |
+
from the root of the project.
|
115 |
+
|
116 |
+
Building the docs
|
117 |
+
=================
|
118 |
+
|
119 |
+
To build the docs you need to have sphinx (>=1.4) and some dependencies
|
120 |
+
installed::
|
121 |
+
|
122 |
+
pip install -U -r .readthedocs-requirements.txt
|
123 |
+
|
124 |
+
The docs can then be built with the following command::
|
125 |
+
|
126 |
+
make doc
|
127 |
+
|
128 |
+
The html docs are located in the ``doc/_build/html`` directory.
|
129 |
+
|
130 |
+
|
131 |
+
Making a source tarball
|
132 |
+
=======================
|
133 |
+
|
134 |
+
To create a source tarball, eg for packaging or distributing, run the
|
135 |
+
following command::
|
136 |
+
|
137 |
+
python setup.py sdist
|
138 |
+
|
139 |
+
The tarball will be created in the `dist` directory. This command will
|
140 |
+
compile the docs, and the resulting tarball can be installed with
|
141 |
+
no extra dependencies than the Python standard library. You will need
|
142 |
+
setuptool and sphinx.
|
143 |
+
|
144 |
+
Making a release and uploading it to PyPI
|
145 |
+
=========================================
|
146 |
+
|
147 |
+
This command is only run by project manager, to make a release, and
|
148 |
+
upload in to PyPI::
|
149 |
+
|
150 |
+
python setup.py sdist bdist_wheel
|
151 |
+
twine upload dist/*
|
152 |
+
|
153 |
+
|
154 |
+
Note that the documentation should automatically get updated at each git
|
155 |
+
push. If that is not the case, try building th doc locally and resolve
|
156 |
+
any doc build error (in particular when running the examples).
|
157 |
+
|
158 |
+
Updating the changelog
|
159 |
+
======================
|
160 |
+
|
161 |
+
Changes are listed in the CHANGES.rst file. They must be manually updated
|
162 |
+
but, the following git command may be used to generate the lines::
|
163 |
+
|
164 |
+
git log --abbrev-commit --date=short --no-merges --sparse
|
165 |
+
|
llmeval-env/lib/python3.10/site-packages/more_itertools/__init__.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""More routines for operating on iterables, beyond itertools"""
|
2 |
+
|
3 |
+
from .more import * # noqa
|
4 |
+
from .recipes import * # noqa
|
5 |
+
|
6 |
+
__version__ = '10.2.0'
|
llmeval-env/lib/python3.10/site-packages/more_itertools/__init__.pyi
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
from .more import *
|
2 |
+
from .recipes import *
|
llmeval-env/lib/python3.10/site-packages/more_itertools/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (329 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/more_itertools/__pycache__/more.cpython-310.pyc
ADDED
Binary file (133 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/more_itertools/__pycache__/recipes.cpython-310.pyc
ADDED
Binary file (28.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/more_itertools/more.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|
llmeval-env/lib/python3.10/site-packages/more_itertools/more.pyi
ADDED
@@ -0,0 +1,695 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Stubs for more_itertools.more"""
|
2 |
+
from __future__ import annotations
|
3 |
+
|
4 |
+
from types import TracebackType
|
5 |
+
from typing import (
|
6 |
+
Any,
|
7 |
+
Callable,
|
8 |
+
Container,
|
9 |
+
ContextManager,
|
10 |
+
Generic,
|
11 |
+
Hashable,
|
12 |
+
Iterable,
|
13 |
+
Iterator,
|
14 |
+
overload,
|
15 |
+
Reversible,
|
16 |
+
Sequence,
|
17 |
+
Sized,
|
18 |
+
Type,
|
19 |
+
TypeVar,
|
20 |
+
type_check_only,
|
21 |
+
)
|
22 |
+
from typing_extensions import Protocol
|
23 |
+
|
24 |
+
# Type and type variable definitions
|
25 |
+
_T = TypeVar('_T')
|
26 |
+
_T1 = TypeVar('_T1')
|
27 |
+
_T2 = TypeVar('_T2')
|
28 |
+
_U = TypeVar('_U')
|
29 |
+
_V = TypeVar('_V')
|
30 |
+
_W = TypeVar('_W')
|
31 |
+
_T_co = TypeVar('_T_co', covariant=True)
|
32 |
+
_GenFn = TypeVar('_GenFn', bound=Callable[..., Iterator[Any]])
|
33 |
+
_Raisable = BaseException | Type[BaseException]
|
34 |
+
|
35 |
+
@type_check_only
|
36 |
+
class _SizedIterable(Protocol[_T_co], Sized, Iterable[_T_co]): ...
|
37 |
+
|
38 |
+
@type_check_only
|
39 |
+
class _SizedReversible(Protocol[_T_co], Sized, Reversible[_T_co]): ...
|
40 |
+
|
41 |
+
@type_check_only
|
42 |
+
class _SupportsSlicing(Protocol[_T_co]):
|
43 |
+
def __getitem__(self, __k: slice) -> _T_co: ...
|
44 |
+
|
45 |
+
def chunked(
|
46 |
+
iterable: Iterable[_T], n: int | None, strict: bool = ...
|
47 |
+
) -> Iterator[list[_T]]: ...
|
48 |
+
@overload
|
49 |
+
def first(iterable: Iterable[_T]) -> _T: ...
|
50 |
+
@overload
|
51 |
+
def first(iterable: Iterable[_T], default: _U) -> _T | _U: ...
|
52 |
+
@overload
|
53 |
+
def last(iterable: Iterable[_T]) -> _T: ...
|
54 |
+
@overload
|
55 |
+
def last(iterable: Iterable[_T], default: _U) -> _T | _U: ...
|
56 |
+
@overload
|
57 |
+
def nth_or_last(iterable: Iterable[_T], n: int) -> _T: ...
|
58 |
+
@overload
|
59 |
+
def nth_or_last(iterable: Iterable[_T], n: int, default: _U) -> _T | _U: ...
|
60 |
+
|
61 |
+
class peekable(Generic[_T], Iterator[_T]):
|
62 |
+
def __init__(self, iterable: Iterable[_T]) -> None: ...
|
63 |
+
def __iter__(self) -> peekable[_T]: ...
|
64 |
+
def __bool__(self) -> bool: ...
|
65 |
+
@overload
|
66 |
+
def peek(self) -> _T: ...
|
67 |
+
@overload
|
68 |
+
def peek(self, default: _U) -> _T | _U: ...
|
69 |
+
def prepend(self, *items: _T) -> None: ...
|
70 |
+
def __next__(self) -> _T: ...
|
71 |
+
@overload
|
72 |
+
def __getitem__(self, index: int) -> _T: ...
|
73 |
+
@overload
|
74 |
+
def __getitem__(self, index: slice) -> list[_T]: ...
|
75 |
+
|
76 |
+
def consumer(func: _GenFn) -> _GenFn: ...
|
77 |
+
def ilen(iterable: Iterable[_T]) -> int: ...
|
78 |
+
def iterate(func: Callable[[_T], _T], start: _T) -> Iterator[_T]: ...
|
79 |
+
def with_iter(
|
80 |
+
context_manager: ContextManager[Iterable[_T]],
|
81 |
+
) -> Iterator[_T]: ...
|
82 |
+
def one(
|
83 |
+
iterable: Iterable[_T],
|
84 |
+
too_short: _Raisable | None = ...,
|
85 |
+
too_long: _Raisable | None = ...,
|
86 |
+
) -> _T: ...
|
87 |
+
def raise_(exception: _Raisable, *args: Any) -> None: ...
|
88 |
+
def strictly_n(
|
89 |
+
iterable: Iterable[_T],
|
90 |
+
n: int,
|
91 |
+
too_short: _GenFn | None = ...,
|
92 |
+
too_long: _GenFn | None = ...,
|
93 |
+
) -> list[_T]: ...
|
94 |
+
def distinct_permutations(
|
95 |
+
iterable: Iterable[_T], r: int | None = ...
|
96 |
+
) -> Iterator[tuple[_T, ...]]: ...
|
97 |
+
def intersperse(
|
98 |
+
e: _U, iterable: Iterable[_T], n: int = ...
|
99 |
+
) -> Iterator[_T | _U]: ...
|
100 |
+
def unique_to_each(*iterables: Iterable[_T]) -> list[list[_T]]: ...
|
101 |
+
@overload
|
102 |
+
def windowed(
|
103 |
+
seq: Iterable[_T], n: int, *, step: int = ...
|
104 |
+
) -> Iterator[tuple[_T | None, ...]]: ...
|
105 |
+
@overload
|
106 |
+
def windowed(
|
107 |
+
seq: Iterable[_T], n: int, fillvalue: _U, step: int = ...
|
108 |
+
) -> Iterator[tuple[_T | _U, ...]]: ...
|
109 |
+
def substrings(iterable: Iterable[_T]) -> Iterator[tuple[_T, ...]]: ...
|
110 |
+
def substrings_indexes(
|
111 |
+
seq: Sequence[_T], reverse: bool = ...
|
112 |
+
) -> Iterator[tuple[Sequence[_T], int, int]]: ...
|
113 |
+
|
114 |
+
class bucket(Generic[_T, _U], Container[_U]):
|
115 |
+
def __init__(
|
116 |
+
self,
|
117 |
+
iterable: Iterable[_T],
|
118 |
+
key: Callable[[_T], _U],
|
119 |
+
validator: Callable[[_U], object] | None = ...,
|
120 |
+
) -> None: ...
|
121 |
+
def __contains__(self, value: object) -> bool: ...
|
122 |
+
def __iter__(self) -> Iterator[_U]: ...
|
123 |
+
def __getitem__(self, value: object) -> Iterator[_T]: ...
|
124 |
+
|
125 |
+
def spy(
|
126 |
+
iterable: Iterable[_T], n: int = ...
|
127 |
+
) -> tuple[list[_T], Iterator[_T]]: ...
|
128 |
+
def interleave(*iterables: Iterable[_T]) -> Iterator[_T]: ...
|
129 |
+
def interleave_longest(*iterables: Iterable[_T]) -> Iterator[_T]: ...
|
130 |
+
def interleave_evenly(
|
131 |
+
iterables: list[Iterable[_T]], lengths: list[int] | None = ...
|
132 |
+
) -> Iterator[_T]: ...
|
133 |
+
def collapse(
|
134 |
+
iterable: Iterable[Any],
|
135 |
+
base_type: type | None = ...,
|
136 |
+
levels: int | None = ...,
|
137 |
+
) -> Iterator[Any]: ...
|
138 |
+
@overload
|
139 |
+
def side_effect(
|
140 |
+
func: Callable[[_T], object],
|
141 |
+
iterable: Iterable[_T],
|
142 |
+
chunk_size: None = ...,
|
143 |
+
before: Callable[[], object] | None = ...,
|
144 |
+
after: Callable[[], object] | None = ...,
|
145 |
+
) -> Iterator[_T]: ...
|
146 |
+
@overload
|
147 |
+
def side_effect(
|
148 |
+
func: Callable[[list[_T]], object],
|
149 |
+
iterable: Iterable[_T],
|
150 |
+
chunk_size: int,
|
151 |
+
before: Callable[[], object] | None = ...,
|
152 |
+
after: Callable[[], object] | None = ...,
|
153 |
+
) -> Iterator[_T]: ...
|
154 |
+
def sliced(
|
155 |
+
seq: _SupportsSlicing[_T], n: int, strict: bool = ...
|
156 |
+
) -> Iterator[_T]: ...
|
157 |
+
def split_at(
|
158 |
+
iterable: Iterable[_T],
|
159 |
+
pred: Callable[[_T], object],
|
160 |
+
maxsplit: int = ...,
|
161 |
+
keep_separator: bool = ...,
|
162 |
+
) -> Iterator[list[_T]]: ...
|
163 |
+
def split_before(
|
164 |
+
iterable: Iterable[_T], pred: Callable[[_T], object], maxsplit: int = ...
|
165 |
+
) -> Iterator[list[_T]]: ...
|
166 |
+
def split_after(
|
167 |
+
iterable: Iterable[_T], pred: Callable[[_T], object], maxsplit: int = ...
|
168 |
+
) -> Iterator[list[_T]]: ...
|
169 |
+
def split_when(
|
170 |
+
iterable: Iterable[_T],
|
171 |
+
pred: Callable[[_T, _T], object],
|
172 |
+
maxsplit: int = ...,
|
173 |
+
) -> Iterator[list[_T]]: ...
|
174 |
+
def split_into(
|
175 |
+
iterable: Iterable[_T], sizes: Iterable[int | None]
|
176 |
+
) -> Iterator[list[_T]]: ...
|
177 |
+
@overload
|
178 |
+
def padded(
|
179 |
+
iterable: Iterable[_T],
|
180 |
+
*,
|
181 |
+
n: int | None = ...,
|
182 |
+
next_multiple: bool = ...,
|
183 |
+
) -> Iterator[_T | None]: ...
|
184 |
+
@overload
|
185 |
+
def padded(
|
186 |
+
iterable: Iterable[_T],
|
187 |
+
fillvalue: _U,
|
188 |
+
n: int | None = ...,
|
189 |
+
next_multiple: bool = ...,
|
190 |
+
) -> Iterator[_T | _U]: ...
|
191 |
+
@overload
|
192 |
+
def repeat_last(iterable: Iterable[_T]) -> Iterator[_T]: ...
|
193 |
+
@overload
|
194 |
+
def repeat_last(iterable: Iterable[_T], default: _U) -> Iterator[_T | _U]: ...
|
195 |
+
def distribute(n: int, iterable: Iterable[_T]) -> list[Iterator[_T]]: ...
|
196 |
+
@overload
|
197 |
+
def stagger(
|
198 |
+
iterable: Iterable[_T],
|
199 |
+
offsets: _SizedIterable[int] = ...,
|
200 |
+
longest: bool = ...,
|
201 |
+
) -> Iterator[tuple[_T | None, ...]]: ...
|
202 |
+
@overload
|
203 |
+
def stagger(
|
204 |
+
iterable: Iterable[_T],
|
205 |
+
offsets: _SizedIterable[int] = ...,
|
206 |
+
longest: bool = ...,
|
207 |
+
fillvalue: _U = ...,
|
208 |
+
) -> Iterator[tuple[_T | _U, ...]]: ...
|
209 |
+
|
210 |
+
class UnequalIterablesError(ValueError):
|
211 |
+
def __init__(self, details: tuple[int, int, int] | None = ...) -> None: ...
|
212 |
+
|
213 |
+
@overload
|
214 |
+
def zip_equal(__iter1: Iterable[_T1]) -> Iterator[tuple[_T1]]: ...
|
215 |
+
@overload
|
216 |
+
def zip_equal(
|
217 |
+
__iter1: Iterable[_T1], __iter2: Iterable[_T2]
|
218 |
+
) -> Iterator[tuple[_T1, _T2]]: ...
|
219 |
+
@overload
|
220 |
+
def zip_equal(
|
221 |
+
__iter1: Iterable[_T],
|
222 |
+
__iter2: Iterable[_T],
|
223 |
+
__iter3: Iterable[_T],
|
224 |
+
*iterables: Iterable[_T],
|
225 |
+
) -> Iterator[tuple[_T, ...]]: ...
|
226 |
+
@overload
|
227 |
+
def zip_offset(
|
228 |
+
__iter1: Iterable[_T1],
|
229 |
+
*,
|
230 |
+
offsets: _SizedIterable[int],
|
231 |
+
longest: bool = ...,
|
232 |
+
fillvalue: None = None,
|
233 |
+
) -> Iterator[tuple[_T1 | None]]: ...
|
234 |
+
@overload
|
235 |
+
def zip_offset(
|
236 |
+
__iter1: Iterable[_T1],
|
237 |
+
__iter2: Iterable[_T2],
|
238 |
+
*,
|
239 |
+
offsets: _SizedIterable[int],
|
240 |
+
longest: bool = ...,
|
241 |
+
fillvalue: None = None,
|
242 |
+
) -> Iterator[tuple[_T1 | None, _T2 | None]]: ...
|
243 |
+
@overload
|
244 |
+
def zip_offset(
|
245 |
+
__iter1: Iterable[_T],
|
246 |
+
__iter2: Iterable[_T],
|
247 |
+
__iter3: Iterable[_T],
|
248 |
+
*iterables: Iterable[_T],
|
249 |
+
offsets: _SizedIterable[int],
|
250 |
+
longest: bool = ...,
|
251 |
+
fillvalue: None = None,
|
252 |
+
) -> Iterator[tuple[_T | None, ...]]: ...
|
253 |
+
@overload
|
254 |
+
def zip_offset(
|
255 |
+
__iter1: Iterable[_T1],
|
256 |
+
*,
|
257 |
+
offsets: _SizedIterable[int],
|
258 |
+
longest: bool = ...,
|
259 |
+
fillvalue: _U,
|
260 |
+
) -> Iterator[tuple[_T1 | _U]]: ...
|
261 |
+
@overload
|
262 |
+
def zip_offset(
|
263 |
+
__iter1: Iterable[_T1],
|
264 |
+
__iter2: Iterable[_T2],
|
265 |
+
*,
|
266 |
+
offsets: _SizedIterable[int],
|
267 |
+
longest: bool = ...,
|
268 |
+
fillvalue: _U,
|
269 |
+
) -> Iterator[tuple[_T1 | _U, _T2 | _U]]: ...
|
270 |
+
@overload
|
271 |
+
def zip_offset(
|
272 |
+
__iter1: Iterable[_T],
|
273 |
+
__iter2: Iterable[_T],
|
274 |
+
__iter3: Iterable[_T],
|
275 |
+
*iterables: Iterable[_T],
|
276 |
+
offsets: _SizedIterable[int],
|
277 |
+
longest: bool = ...,
|
278 |
+
fillvalue: _U,
|
279 |
+
) -> Iterator[tuple[_T | _U, ...]]: ...
|
280 |
+
def sort_together(
|
281 |
+
iterables: Iterable[Iterable[_T]],
|
282 |
+
key_list: Iterable[int] = ...,
|
283 |
+
key: Callable[..., Any] | None = ...,
|
284 |
+
reverse: bool = ...,
|
285 |
+
) -> list[tuple[_T, ...]]: ...
|
286 |
+
def unzip(iterable: Iterable[Sequence[_T]]) -> tuple[Iterator[_T], ...]: ...
|
287 |
+
def divide(n: int, iterable: Iterable[_T]) -> list[Iterator[_T]]: ...
|
288 |
+
def always_iterable(
|
289 |
+
obj: object,
|
290 |
+
base_type: type | tuple[type | tuple[Any, ...], ...] | None = ...,
|
291 |
+
) -> Iterator[Any]: ...
|
292 |
+
def adjacent(
|
293 |
+
predicate: Callable[[_T], bool],
|
294 |
+
iterable: Iterable[_T],
|
295 |
+
distance: int = ...,
|
296 |
+
) -> Iterator[tuple[bool, _T]]: ...
|
297 |
+
@overload
|
298 |
+
def groupby_transform(
|
299 |
+
iterable: Iterable[_T],
|
300 |
+
keyfunc: None = None,
|
301 |
+
valuefunc: None = None,
|
302 |
+
reducefunc: None = None,
|
303 |
+
) -> Iterator[tuple[_T, Iterator[_T]]]: ...
|
304 |
+
@overload
|
305 |
+
def groupby_transform(
|
306 |
+
iterable: Iterable[_T],
|
307 |
+
keyfunc: Callable[[_T], _U],
|
308 |
+
valuefunc: None,
|
309 |
+
reducefunc: None,
|
310 |
+
) -> Iterator[tuple[_U, Iterator[_T]]]: ...
|
311 |
+
@overload
|
312 |
+
def groupby_transform(
|
313 |
+
iterable: Iterable[_T],
|
314 |
+
keyfunc: None,
|
315 |
+
valuefunc: Callable[[_T], _V],
|
316 |
+
reducefunc: None,
|
317 |
+
) -> Iterable[tuple[_T, Iterable[_V]]]: ...
|
318 |
+
@overload
|
319 |
+
def groupby_transform(
|
320 |
+
iterable: Iterable[_T],
|
321 |
+
keyfunc: Callable[[_T], _U],
|
322 |
+
valuefunc: Callable[[_T], _V],
|
323 |
+
reducefunc: None,
|
324 |
+
) -> Iterable[tuple[_U, Iterator[_V]]]: ...
|
325 |
+
@overload
|
326 |
+
def groupby_transform(
|
327 |
+
iterable: Iterable[_T],
|
328 |
+
keyfunc: None,
|
329 |
+
valuefunc: None,
|
330 |
+
reducefunc: Callable[[Iterator[_T]], _W],
|
331 |
+
) -> Iterable[tuple[_T, _W]]: ...
|
332 |
+
@overload
|
333 |
+
def groupby_transform(
|
334 |
+
iterable: Iterable[_T],
|
335 |
+
keyfunc: Callable[[_T], _U],
|
336 |
+
valuefunc: None,
|
337 |
+
reducefunc: Callable[[Iterator[_T]], _W],
|
338 |
+
) -> Iterable[tuple[_U, _W]]: ...
|
339 |
+
@overload
|
340 |
+
def groupby_transform(
|
341 |
+
iterable: Iterable[_T],
|
342 |
+
keyfunc: None,
|
343 |
+
valuefunc: Callable[[_T], _V],
|
344 |
+
reducefunc: Callable[[Iterable[_V]], _W],
|
345 |
+
) -> Iterable[tuple[_T, _W]]: ...
|
346 |
+
@overload
|
347 |
+
def groupby_transform(
|
348 |
+
iterable: Iterable[_T],
|
349 |
+
keyfunc: Callable[[_T], _U],
|
350 |
+
valuefunc: Callable[[_T], _V],
|
351 |
+
reducefunc: Callable[[Iterable[_V]], _W],
|
352 |
+
) -> Iterable[tuple[_U, _W]]: ...
|
353 |
+
|
354 |
+
class numeric_range(Generic[_T, _U], Sequence[_T], Hashable, Reversible[_T]):
|
355 |
+
@overload
|
356 |
+
def __init__(self, __stop: _T) -> None: ...
|
357 |
+
@overload
|
358 |
+
def __init__(self, __start: _T, __stop: _T) -> None: ...
|
359 |
+
@overload
|
360 |
+
def __init__(self, __start: _T, __stop: _T, __step: _U) -> None: ...
|
361 |
+
def __bool__(self) -> bool: ...
|
362 |
+
def __contains__(self, elem: object) -> bool: ...
|
363 |
+
def __eq__(self, other: object) -> bool: ...
|
364 |
+
@overload
|
365 |
+
def __getitem__(self, key: int) -> _T: ...
|
366 |
+
@overload
|
367 |
+
def __getitem__(self, key: slice) -> numeric_range[_T, _U]: ...
|
368 |
+
def __hash__(self) -> int: ...
|
369 |
+
def __iter__(self) -> Iterator[_T]: ...
|
370 |
+
def __len__(self) -> int: ...
|
371 |
+
def __reduce__(
|
372 |
+
self,
|
373 |
+
) -> tuple[Type[numeric_range[_T, _U]], tuple[_T, _T, _U]]: ...
|
374 |
+
def __repr__(self) -> str: ...
|
375 |
+
def __reversed__(self) -> Iterator[_T]: ...
|
376 |
+
def count(self, value: _T) -> int: ...
|
377 |
+
def index(self, value: _T) -> int: ... # type: ignore
|
378 |
+
|
379 |
+
def count_cycle(
|
380 |
+
iterable: Iterable[_T], n: int | None = ...
|
381 |
+
) -> Iterable[tuple[int, _T]]: ...
|
382 |
+
def mark_ends(
|
383 |
+
iterable: Iterable[_T],
|
384 |
+
) -> Iterable[tuple[bool, bool, _T]]: ...
|
385 |
+
def locate(
|
386 |
+
iterable: Iterable[_T],
|
387 |
+
pred: Callable[..., Any] = ...,
|
388 |
+
window_size: int | None = ...,
|
389 |
+
) -> Iterator[int]: ...
|
390 |
+
def lstrip(
|
391 |
+
iterable: Iterable[_T], pred: Callable[[_T], object]
|
392 |
+
) -> Iterator[_T]: ...
|
393 |
+
def rstrip(
|
394 |
+
iterable: Iterable[_T], pred: Callable[[_T], object]
|
395 |
+
) -> Iterator[_T]: ...
|
396 |
+
def strip(
|
397 |
+
iterable: Iterable[_T], pred: Callable[[_T], object]
|
398 |
+
) -> Iterator[_T]: ...
|
399 |
+
|
400 |
+
class islice_extended(Generic[_T], Iterator[_T]):
|
401 |
+
def __init__(self, iterable: Iterable[_T], *args: int | None) -> None: ...
|
402 |
+
def __iter__(self) -> islice_extended[_T]: ...
|
403 |
+
def __next__(self) -> _T: ...
|
404 |
+
def __getitem__(self, index: slice) -> islice_extended[_T]: ...
|
405 |
+
|
406 |
+
def always_reversible(iterable: Iterable[_T]) -> Iterator[_T]: ...
|
407 |
+
def consecutive_groups(
|
408 |
+
iterable: Iterable[_T], ordering: Callable[[_T], int] = ...
|
409 |
+
) -> Iterator[Iterator[_T]]: ...
|
410 |
+
@overload
|
411 |
+
def difference(
|
412 |
+
iterable: Iterable[_T],
|
413 |
+
func: Callable[[_T, _T], _U] = ...,
|
414 |
+
*,
|
415 |
+
initial: None = ...,
|
416 |
+
) -> Iterator[_T | _U]: ...
|
417 |
+
@overload
|
418 |
+
def difference(
|
419 |
+
iterable: Iterable[_T], func: Callable[[_T, _T], _U] = ..., *, initial: _U
|
420 |
+
) -> Iterator[_U]: ...
|
421 |
+
|
422 |
+
class SequenceView(Generic[_T], Sequence[_T]):
|
423 |
+
def __init__(self, target: Sequence[_T]) -> None: ...
|
424 |
+
@overload
|
425 |
+
def __getitem__(self, index: int) -> _T: ...
|
426 |
+
@overload
|
427 |
+
def __getitem__(self, index: slice) -> Sequence[_T]: ...
|
428 |
+
def __len__(self) -> int: ...
|
429 |
+
|
430 |
+
class seekable(Generic[_T], Iterator[_T]):
|
431 |
+
def __init__(
|
432 |
+
self, iterable: Iterable[_T], maxlen: int | None = ...
|
433 |
+
) -> None: ...
|
434 |
+
def __iter__(self) -> seekable[_T]: ...
|
435 |
+
def __next__(self) -> _T: ...
|
436 |
+
def __bool__(self) -> bool: ...
|
437 |
+
@overload
|
438 |
+
def peek(self) -> _T: ...
|
439 |
+
@overload
|
440 |
+
def peek(self, default: _U) -> _T | _U: ...
|
441 |
+
def elements(self) -> SequenceView[_T]: ...
|
442 |
+
def seek(self, index: int) -> None: ...
|
443 |
+
def relative_seek(self, count: int) -> None: ...
|
444 |
+
|
445 |
+
class run_length:
|
446 |
+
@staticmethod
|
447 |
+
def encode(iterable: Iterable[_T]) -> Iterator[tuple[_T, int]]: ...
|
448 |
+
@staticmethod
|
449 |
+
def decode(iterable: Iterable[tuple[_T, int]]) -> Iterator[_T]: ...
|
450 |
+
|
451 |
+
def exactly_n(
|
452 |
+
iterable: Iterable[_T], n: int, predicate: Callable[[_T], object] = ...
|
453 |
+
) -> bool: ...
|
454 |
+
def circular_shifts(iterable: Iterable[_T]) -> list[tuple[_T, ...]]: ...
|
455 |
+
def make_decorator(
|
456 |
+
wrapping_func: Callable[..., _U], result_index: int = ...
|
457 |
+
) -> Callable[..., Callable[[Callable[..., Any]], Callable[..., _U]]]: ...
|
458 |
+
@overload
|
459 |
+
def map_reduce(
|
460 |
+
iterable: Iterable[_T],
|
461 |
+
keyfunc: Callable[[_T], _U],
|
462 |
+
valuefunc: None = ...,
|
463 |
+
reducefunc: None = ...,
|
464 |
+
) -> dict[_U, list[_T]]: ...
|
465 |
+
@overload
|
466 |
+
def map_reduce(
|
467 |
+
iterable: Iterable[_T],
|
468 |
+
keyfunc: Callable[[_T], _U],
|
469 |
+
valuefunc: Callable[[_T], _V],
|
470 |
+
reducefunc: None = ...,
|
471 |
+
) -> dict[_U, list[_V]]: ...
|
472 |
+
@overload
|
473 |
+
def map_reduce(
|
474 |
+
iterable: Iterable[_T],
|
475 |
+
keyfunc: Callable[[_T], _U],
|
476 |
+
valuefunc: None = ...,
|
477 |
+
reducefunc: Callable[[list[_T]], _W] = ...,
|
478 |
+
) -> dict[_U, _W]: ...
|
479 |
+
@overload
|
480 |
+
def map_reduce(
|
481 |
+
iterable: Iterable[_T],
|
482 |
+
keyfunc: Callable[[_T], _U],
|
483 |
+
valuefunc: Callable[[_T], _V],
|
484 |
+
reducefunc: Callable[[list[_V]], _W],
|
485 |
+
) -> dict[_U, _W]: ...
|
486 |
+
def rlocate(
|
487 |
+
iterable: Iterable[_T],
|
488 |
+
pred: Callable[..., object] = ...,
|
489 |
+
window_size: int | None = ...,
|
490 |
+
) -> Iterator[int]: ...
|
491 |
+
def replace(
|
492 |
+
iterable: Iterable[_T],
|
493 |
+
pred: Callable[..., object],
|
494 |
+
substitutes: Iterable[_U],
|
495 |
+
count: int | None = ...,
|
496 |
+
window_size: int = ...,
|
497 |
+
) -> Iterator[_T | _U]: ...
|
498 |
+
def partitions(iterable: Iterable[_T]) -> Iterator[list[list[_T]]]: ...
|
499 |
+
def set_partitions(
|
500 |
+
iterable: Iterable[_T], k: int | None = ...
|
501 |
+
) -> Iterator[list[list[_T]]]: ...
|
502 |
+
|
503 |
+
class time_limited(Generic[_T], Iterator[_T]):
|
504 |
+
def __init__(
|
505 |
+
self, limit_seconds: float, iterable: Iterable[_T]
|
506 |
+
) -> None: ...
|
507 |
+
def __iter__(self) -> islice_extended[_T]: ...
|
508 |
+
def __next__(self) -> _T: ...
|
509 |
+
|
510 |
+
@overload
|
511 |
+
def only(
|
512 |
+
iterable: Iterable[_T], *, too_long: _Raisable | None = ...
|
513 |
+
) -> _T | None: ...
|
514 |
+
@overload
|
515 |
+
def only(
|
516 |
+
iterable: Iterable[_T], default: _U, too_long: _Raisable | None = ...
|
517 |
+
) -> _T | _U: ...
|
518 |
+
def ichunked(iterable: Iterable[_T], n: int) -> Iterator[Iterator[_T]]: ...
|
519 |
+
def distinct_combinations(
|
520 |
+
iterable: Iterable[_T], r: int
|
521 |
+
) -> Iterator[tuple[_T, ...]]: ...
|
522 |
+
def filter_except(
|
523 |
+
validator: Callable[[Any], object],
|
524 |
+
iterable: Iterable[_T],
|
525 |
+
*exceptions: Type[BaseException],
|
526 |
+
) -> Iterator[_T]: ...
|
527 |
+
def map_except(
|
528 |
+
function: Callable[[Any], _U],
|
529 |
+
iterable: Iterable[_T],
|
530 |
+
*exceptions: Type[BaseException],
|
531 |
+
) -> Iterator[_U]: ...
|
532 |
+
def map_if(
|
533 |
+
iterable: Iterable[Any],
|
534 |
+
pred: Callable[[Any], bool],
|
535 |
+
func: Callable[[Any], Any],
|
536 |
+
func_else: Callable[[Any], Any] | None = ...,
|
537 |
+
) -> Iterator[Any]: ...
|
538 |
+
def sample(
|
539 |
+
iterable: Iterable[_T],
|
540 |
+
k: int,
|
541 |
+
weights: Iterable[float] | None = ...,
|
542 |
+
) -> list[_T]: ...
|
543 |
+
def is_sorted(
|
544 |
+
iterable: Iterable[_T],
|
545 |
+
key: Callable[[_T], _U] | None = ...,
|
546 |
+
reverse: bool = False,
|
547 |
+
strict: bool = False,
|
548 |
+
) -> bool: ...
|
549 |
+
|
550 |
+
class AbortThread(BaseException):
|
551 |
+
pass
|
552 |
+
|
553 |
+
class callback_iter(Generic[_T], Iterator[_T]):
|
554 |
+
def __init__(
|
555 |
+
self,
|
556 |
+
func: Callable[..., Any],
|
557 |
+
callback_kwd: str = ...,
|
558 |
+
wait_seconds: float = ...,
|
559 |
+
) -> None: ...
|
560 |
+
def __enter__(self) -> callback_iter[_T]: ...
|
561 |
+
def __exit__(
|
562 |
+
self,
|
563 |
+
exc_type: Type[BaseException] | None,
|
564 |
+
exc_value: BaseException | None,
|
565 |
+
traceback: TracebackType | None,
|
566 |
+
) -> bool | None: ...
|
567 |
+
def __iter__(self) -> callback_iter[_T]: ...
|
568 |
+
def __next__(self) -> _T: ...
|
569 |
+
def _reader(self) -> Iterator[_T]: ...
|
570 |
+
@property
|
571 |
+
def done(self) -> bool: ...
|
572 |
+
@property
|
573 |
+
def result(self) -> Any: ...
|
574 |
+
|
575 |
+
def windowed_complete(
|
576 |
+
iterable: Iterable[_T], n: int
|
577 |
+
) -> Iterator[tuple[_T, ...]]: ...
|
578 |
+
def all_unique(
|
579 |
+
iterable: Iterable[_T], key: Callable[[_T], _U] | None = ...
|
580 |
+
) -> bool: ...
|
581 |
+
def nth_product(index: int, *args: Iterable[_T]) -> tuple[_T, ...]: ...
|
582 |
+
def nth_combination_with_replacement(
|
583 |
+
iterable: Iterable[_T], r: int, index: int
|
584 |
+
) -> tuple[_T, ...]: ...
|
585 |
+
def nth_permutation(
|
586 |
+
iterable: Iterable[_T], r: int, index: int
|
587 |
+
) -> tuple[_T, ...]: ...
|
588 |
+
def value_chain(*args: _T | Iterable[_T]) -> Iterable[_T]: ...
|
589 |
+
def product_index(element: Iterable[_T], *args: Iterable[_T]) -> int: ...
|
590 |
+
def combination_index(
|
591 |
+
element: Iterable[_T], iterable: Iterable[_T]
|
592 |
+
) -> int: ...
|
593 |
+
def combination_with_replacement_index(
|
594 |
+
element: Iterable[_T], iterable: Iterable[_T]
|
595 |
+
) -> int: ...
|
596 |
+
def permutation_index(
|
597 |
+
element: Iterable[_T], iterable: Iterable[_T]
|
598 |
+
) -> int: ...
|
599 |
+
def repeat_each(iterable: Iterable[_T], n: int = ...) -> Iterator[_T]: ...
|
600 |
+
|
601 |
+
class countable(Generic[_T], Iterator[_T]):
|
602 |
+
def __init__(self, iterable: Iterable[_T]) -> None: ...
|
603 |
+
def __iter__(self) -> countable[_T]: ...
|
604 |
+
def __next__(self) -> _T: ...
|
605 |
+
|
606 |
+
def chunked_even(iterable: Iterable[_T], n: int) -> Iterator[list[_T]]: ...
|
607 |
+
def zip_broadcast(
|
608 |
+
*objects: _T | Iterable[_T],
|
609 |
+
scalar_types: type | tuple[type | tuple[Any, ...], ...] | None = ...,
|
610 |
+
strict: bool = ...,
|
611 |
+
) -> Iterable[tuple[_T, ...]]: ...
|
612 |
+
def unique_in_window(
|
613 |
+
iterable: Iterable[_T], n: int, key: Callable[[_T], _U] | None = ...
|
614 |
+
) -> Iterator[_T]: ...
|
615 |
+
def duplicates_everseen(
|
616 |
+
iterable: Iterable[_T], key: Callable[[_T], _U] | None = ...
|
617 |
+
) -> Iterator[_T]: ...
|
618 |
+
def duplicates_justseen(
|
619 |
+
iterable: Iterable[_T], key: Callable[[_T], _U] | None = ...
|
620 |
+
) -> Iterator[_T]: ...
|
621 |
+
def classify_unique(
|
622 |
+
iterable: Iterable[_T], key: Callable[[_T], _U] | None = ...
|
623 |
+
) -> Iterator[tuple[_T, bool, bool]]: ...
|
624 |
+
|
625 |
+
class _SupportsLessThan(Protocol):
|
626 |
+
def __lt__(self, __other: Any) -> bool: ...
|
627 |
+
|
628 |
+
_SupportsLessThanT = TypeVar("_SupportsLessThanT", bound=_SupportsLessThan)
|
629 |
+
|
630 |
+
@overload
|
631 |
+
def minmax(
|
632 |
+
iterable_or_value: Iterable[_SupportsLessThanT], *, key: None = None
|
633 |
+
) -> tuple[_SupportsLessThanT, _SupportsLessThanT]: ...
|
634 |
+
@overload
|
635 |
+
def minmax(
|
636 |
+
iterable_or_value: Iterable[_T], *, key: Callable[[_T], _SupportsLessThan]
|
637 |
+
) -> tuple[_T, _T]: ...
|
638 |
+
@overload
|
639 |
+
def minmax(
|
640 |
+
iterable_or_value: Iterable[_SupportsLessThanT],
|
641 |
+
*,
|
642 |
+
key: None = None,
|
643 |
+
default: _U,
|
644 |
+
) -> _U | tuple[_SupportsLessThanT, _SupportsLessThanT]: ...
|
645 |
+
@overload
|
646 |
+
def minmax(
|
647 |
+
iterable_or_value: Iterable[_T],
|
648 |
+
*,
|
649 |
+
key: Callable[[_T], _SupportsLessThan],
|
650 |
+
default: _U,
|
651 |
+
) -> _U | tuple[_T, _T]: ...
|
652 |
+
@overload
|
653 |
+
def minmax(
|
654 |
+
iterable_or_value: _SupportsLessThanT,
|
655 |
+
__other: _SupportsLessThanT,
|
656 |
+
*others: _SupportsLessThanT,
|
657 |
+
) -> tuple[_SupportsLessThanT, _SupportsLessThanT]: ...
|
658 |
+
@overload
|
659 |
+
def minmax(
|
660 |
+
iterable_or_value: _T,
|
661 |
+
__other: _T,
|
662 |
+
*others: _T,
|
663 |
+
key: Callable[[_T], _SupportsLessThan],
|
664 |
+
) -> tuple[_T, _T]: ...
|
665 |
+
def longest_common_prefix(
|
666 |
+
iterables: Iterable[Iterable[_T]],
|
667 |
+
) -> Iterator[_T]: ...
|
668 |
+
def iequals(*iterables: Iterable[Any]) -> bool: ...
|
669 |
+
def constrained_batches(
|
670 |
+
iterable: Iterable[_T],
|
671 |
+
max_size: int,
|
672 |
+
max_count: int | None = ...,
|
673 |
+
get_len: Callable[[_T], object] = ...,
|
674 |
+
strict: bool = ...,
|
675 |
+
) -> Iterator[tuple[_T]]: ...
|
676 |
+
def gray_product(*iterables: Iterable[_T]) -> Iterator[tuple[_T, ...]]: ...
|
677 |
+
def partial_product(*iterables: Iterable[_T]) -> Iterator[tuple[_T, ...]]: ...
|
678 |
+
def takewhile_inclusive(
|
679 |
+
predicate: Callable[[_T], bool], iterable: Iterable[_T]
|
680 |
+
) -> Iterator[_T]: ...
|
681 |
+
def outer_product(
|
682 |
+
func: Callable[[_T, _U], _V],
|
683 |
+
xs: Iterable[_T],
|
684 |
+
ys: Iterable[_U],
|
685 |
+
*args: Any,
|
686 |
+
**kwargs: Any,
|
687 |
+
) -> Iterator[tuple[_V, ...]]: ...
|
688 |
+
def iter_suppress(
|
689 |
+
iterable: Iterable[_T],
|
690 |
+
*exceptions: Type[BaseException],
|
691 |
+
) -> Iterator[_T]: ...
|
692 |
+
def filter_map(
|
693 |
+
func: Callable[[_T], _V | None],
|
694 |
+
iterable: Iterable[_T],
|
695 |
+
) -> Iterator[_V]: ...
|
llmeval-env/lib/python3.10/site-packages/more_itertools/py.typed
ADDED
File without changes
|
llmeval-env/lib/python3.10/site-packages/more_itertools/recipes.py
ADDED
@@ -0,0 +1,1012 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Imported from the recipes section of the itertools documentation.
|
2 |
+
|
3 |
+
All functions taken from the recipes section of the itertools library docs
|
4 |
+
[1]_.
|
5 |
+
Some backward-compatible usability improvements have been made.
|
6 |
+
|
7 |
+
.. [1] http://docs.python.org/library/itertools.html#recipes
|
8 |
+
|
9 |
+
"""
|
10 |
+
import math
|
11 |
+
import operator
|
12 |
+
|
13 |
+
from collections import deque
|
14 |
+
from collections.abc import Sized
|
15 |
+
from functools import partial, reduce
|
16 |
+
from itertools import (
|
17 |
+
chain,
|
18 |
+
combinations,
|
19 |
+
compress,
|
20 |
+
count,
|
21 |
+
cycle,
|
22 |
+
groupby,
|
23 |
+
islice,
|
24 |
+
product,
|
25 |
+
repeat,
|
26 |
+
starmap,
|
27 |
+
tee,
|
28 |
+
zip_longest,
|
29 |
+
)
|
30 |
+
from random import randrange, sample, choice
|
31 |
+
from sys import hexversion
|
32 |
+
|
33 |
+
__all__ = [
|
34 |
+
'all_equal',
|
35 |
+
'batched',
|
36 |
+
'before_and_after',
|
37 |
+
'consume',
|
38 |
+
'convolve',
|
39 |
+
'dotproduct',
|
40 |
+
'first_true',
|
41 |
+
'factor',
|
42 |
+
'flatten',
|
43 |
+
'grouper',
|
44 |
+
'iter_except',
|
45 |
+
'iter_index',
|
46 |
+
'matmul',
|
47 |
+
'ncycles',
|
48 |
+
'nth',
|
49 |
+
'nth_combination',
|
50 |
+
'padnone',
|
51 |
+
'pad_none',
|
52 |
+
'pairwise',
|
53 |
+
'partition',
|
54 |
+
'polynomial_eval',
|
55 |
+
'polynomial_from_roots',
|
56 |
+
'polynomial_derivative',
|
57 |
+
'powerset',
|
58 |
+
'prepend',
|
59 |
+
'quantify',
|
60 |
+
'reshape',
|
61 |
+
'random_combination_with_replacement',
|
62 |
+
'random_combination',
|
63 |
+
'random_permutation',
|
64 |
+
'random_product',
|
65 |
+
'repeatfunc',
|
66 |
+
'roundrobin',
|
67 |
+
'sieve',
|
68 |
+
'sliding_window',
|
69 |
+
'subslices',
|
70 |
+
'sum_of_squares',
|
71 |
+
'tabulate',
|
72 |
+
'tail',
|
73 |
+
'take',
|
74 |
+
'totient',
|
75 |
+
'transpose',
|
76 |
+
'triplewise',
|
77 |
+
'unique_everseen',
|
78 |
+
'unique_justseen',
|
79 |
+
]
|
80 |
+
|
81 |
+
_marker = object()
|
82 |
+
|
83 |
+
|
84 |
+
# zip with strict is available for Python 3.10+
|
85 |
+
try:
|
86 |
+
zip(strict=True)
|
87 |
+
except TypeError:
|
88 |
+
_zip_strict = zip
|
89 |
+
else:
|
90 |
+
_zip_strict = partial(zip, strict=True)
|
91 |
+
|
92 |
+
# math.sumprod is available for Python 3.12+
|
93 |
+
_sumprod = getattr(math, 'sumprod', lambda x, y: dotproduct(x, y))
|
94 |
+
|
95 |
+
|
96 |
+
def take(n, iterable):
|
97 |
+
"""Return first *n* items of the iterable as a list.
|
98 |
+
|
99 |
+
>>> take(3, range(10))
|
100 |
+
[0, 1, 2]
|
101 |
+
|
102 |
+
If there are fewer than *n* items in the iterable, all of them are
|
103 |
+
returned.
|
104 |
+
|
105 |
+
>>> take(10, range(3))
|
106 |
+
[0, 1, 2]
|
107 |
+
|
108 |
+
"""
|
109 |
+
return list(islice(iterable, n))
|
110 |
+
|
111 |
+
|
112 |
+
def tabulate(function, start=0):
|
113 |
+
"""Return an iterator over the results of ``func(start)``,
|
114 |
+
``func(start + 1)``, ``func(start + 2)``...
|
115 |
+
|
116 |
+
*func* should be a function that accepts one integer argument.
|
117 |
+
|
118 |
+
If *start* is not specified it defaults to 0. It will be incremented each
|
119 |
+
time the iterator is advanced.
|
120 |
+
|
121 |
+
>>> square = lambda x: x ** 2
|
122 |
+
>>> iterator = tabulate(square, -3)
|
123 |
+
>>> take(4, iterator)
|
124 |
+
[9, 4, 1, 0]
|
125 |
+
|
126 |
+
"""
|
127 |
+
return map(function, count(start))
|
128 |
+
|
129 |
+
|
130 |
+
def tail(n, iterable):
|
131 |
+
"""Return an iterator over the last *n* items of *iterable*.
|
132 |
+
|
133 |
+
>>> t = tail(3, 'ABCDEFG')
|
134 |
+
>>> list(t)
|
135 |
+
['E', 'F', 'G']
|
136 |
+
|
137 |
+
"""
|
138 |
+
# If the given iterable has a length, then we can use islice to get its
|
139 |
+
# final elements. Note that if the iterable is not actually Iterable,
|
140 |
+
# either islice or deque will throw a TypeError. This is why we don't
|
141 |
+
# check if it is Iterable.
|
142 |
+
if isinstance(iterable, Sized):
|
143 |
+
yield from islice(iterable, max(0, len(iterable) - n), None)
|
144 |
+
else:
|
145 |
+
yield from iter(deque(iterable, maxlen=n))
|
146 |
+
|
147 |
+
|
148 |
+
def consume(iterator, n=None):
|
149 |
+
"""Advance *iterable* by *n* steps. If *n* is ``None``, consume it
|
150 |
+
entirely.
|
151 |
+
|
152 |
+
Efficiently exhausts an iterator without returning values. Defaults to
|
153 |
+
consuming the whole iterator, but an optional second argument may be
|
154 |
+
provided to limit consumption.
|
155 |
+
|
156 |
+
>>> i = (x for x in range(10))
|
157 |
+
>>> next(i)
|
158 |
+
0
|
159 |
+
>>> consume(i, 3)
|
160 |
+
>>> next(i)
|
161 |
+
4
|
162 |
+
>>> consume(i)
|
163 |
+
>>> next(i)
|
164 |
+
Traceback (most recent call last):
|
165 |
+
File "<stdin>", line 1, in <module>
|
166 |
+
StopIteration
|
167 |
+
|
168 |
+
If the iterator has fewer items remaining than the provided limit, the
|
169 |
+
whole iterator will be consumed.
|
170 |
+
|
171 |
+
>>> i = (x for x in range(3))
|
172 |
+
>>> consume(i, 5)
|
173 |
+
>>> next(i)
|
174 |
+
Traceback (most recent call last):
|
175 |
+
File "<stdin>", line 1, in <module>
|
176 |
+
StopIteration
|
177 |
+
|
178 |
+
"""
|
179 |
+
# Use functions that consume iterators at C speed.
|
180 |
+
if n is None:
|
181 |
+
# feed the entire iterator into a zero-length deque
|
182 |
+
deque(iterator, maxlen=0)
|
183 |
+
else:
|
184 |
+
# advance to the empty slice starting at position n
|
185 |
+
next(islice(iterator, n, n), None)
|
186 |
+
|
187 |
+
|
188 |
+
def nth(iterable, n, default=None):
|
189 |
+
"""Returns the nth item or a default value.
|
190 |
+
|
191 |
+
>>> l = range(10)
|
192 |
+
>>> nth(l, 3)
|
193 |
+
3
|
194 |
+
>>> nth(l, 20, "zebra")
|
195 |
+
'zebra'
|
196 |
+
|
197 |
+
"""
|
198 |
+
return next(islice(iterable, n, None), default)
|
199 |
+
|
200 |
+
|
201 |
+
def all_equal(iterable):
|
202 |
+
"""
|
203 |
+
Returns ``True`` if all the elements are equal to each other.
|
204 |
+
|
205 |
+
>>> all_equal('aaaa')
|
206 |
+
True
|
207 |
+
>>> all_equal('aaab')
|
208 |
+
False
|
209 |
+
|
210 |
+
"""
|
211 |
+
g = groupby(iterable)
|
212 |
+
return next(g, True) and not next(g, False)
|
213 |
+
|
214 |
+
|
215 |
+
def quantify(iterable, pred=bool):
|
216 |
+
"""Return the how many times the predicate is true.
|
217 |
+
|
218 |
+
>>> quantify([True, False, True])
|
219 |
+
2
|
220 |
+
|
221 |
+
"""
|
222 |
+
return sum(map(pred, iterable))
|
223 |
+
|
224 |
+
|
225 |
+
def pad_none(iterable):
|
226 |
+
"""Returns the sequence of elements and then returns ``None`` indefinitely.
|
227 |
+
|
228 |
+
>>> take(5, pad_none(range(3)))
|
229 |
+
[0, 1, 2, None, None]
|
230 |
+
|
231 |
+
Useful for emulating the behavior of the built-in :func:`map` function.
|
232 |
+
|
233 |
+
See also :func:`padded`.
|
234 |
+
|
235 |
+
"""
|
236 |
+
return chain(iterable, repeat(None))
|
237 |
+
|
238 |
+
|
239 |
+
padnone = pad_none
|
240 |
+
|
241 |
+
|
242 |
+
def ncycles(iterable, n):
|
243 |
+
"""Returns the sequence elements *n* times
|
244 |
+
|
245 |
+
>>> list(ncycles(["a", "b"], 3))
|
246 |
+
['a', 'b', 'a', 'b', 'a', 'b']
|
247 |
+
|
248 |
+
"""
|
249 |
+
return chain.from_iterable(repeat(tuple(iterable), n))
|
250 |
+
|
251 |
+
|
252 |
+
def dotproduct(vec1, vec2):
|
253 |
+
"""Returns the dot product of the two iterables.
|
254 |
+
|
255 |
+
>>> dotproduct([10, 10], [20, 20])
|
256 |
+
400
|
257 |
+
|
258 |
+
"""
|
259 |
+
return sum(map(operator.mul, vec1, vec2))
|
260 |
+
|
261 |
+
|
262 |
+
def flatten(listOfLists):
|
263 |
+
"""Return an iterator flattening one level of nesting in a list of lists.
|
264 |
+
|
265 |
+
>>> list(flatten([[0, 1], [2, 3]]))
|
266 |
+
[0, 1, 2, 3]
|
267 |
+
|
268 |
+
See also :func:`collapse`, which can flatten multiple levels of nesting.
|
269 |
+
|
270 |
+
"""
|
271 |
+
return chain.from_iterable(listOfLists)
|
272 |
+
|
273 |
+
|
274 |
+
def repeatfunc(func, times=None, *args):
|
275 |
+
"""Call *func* with *args* repeatedly, returning an iterable over the
|
276 |
+
results.
|
277 |
+
|
278 |
+
If *times* is specified, the iterable will terminate after that many
|
279 |
+
repetitions:
|
280 |
+
|
281 |
+
>>> from operator import add
|
282 |
+
>>> times = 4
|
283 |
+
>>> args = 3, 5
|
284 |
+
>>> list(repeatfunc(add, times, *args))
|
285 |
+
[8, 8, 8, 8]
|
286 |
+
|
287 |
+
If *times* is ``None`` the iterable will not terminate:
|
288 |
+
|
289 |
+
>>> from random import randrange
|
290 |
+
>>> times = None
|
291 |
+
>>> args = 1, 11
|
292 |
+
>>> take(6, repeatfunc(randrange, times, *args)) # doctest:+SKIP
|
293 |
+
[2, 4, 8, 1, 8, 4]
|
294 |
+
|
295 |
+
"""
|
296 |
+
if times is None:
|
297 |
+
return starmap(func, repeat(args))
|
298 |
+
return starmap(func, repeat(args, times))
|
299 |
+
|
300 |
+
|
301 |
+
def _pairwise(iterable):
|
302 |
+
"""Returns an iterator of paired items, overlapping, from the original
|
303 |
+
|
304 |
+
>>> take(4, pairwise(count()))
|
305 |
+
[(0, 1), (1, 2), (2, 3), (3, 4)]
|
306 |
+
|
307 |
+
On Python 3.10 and above, this is an alias for :func:`itertools.pairwise`.
|
308 |
+
|
309 |
+
"""
|
310 |
+
a, b = tee(iterable)
|
311 |
+
next(b, None)
|
312 |
+
return zip(a, b)
|
313 |
+
|
314 |
+
|
315 |
+
try:
|
316 |
+
from itertools import pairwise as itertools_pairwise
|
317 |
+
except ImportError:
|
318 |
+
pairwise = _pairwise
|
319 |
+
else:
|
320 |
+
|
321 |
+
def pairwise(iterable):
|
322 |
+
return itertools_pairwise(iterable)
|
323 |
+
|
324 |
+
pairwise.__doc__ = _pairwise.__doc__
|
325 |
+
|
326 |
+
|
327 |
+
class UnequalIterablesError(ValueError):
|
328 |
+
def __init__(self, details=None):
|
329 |
+
msg = 'Iterables have different lengths'
|
330 |
+
if details is not None:
|
331 |
+
msg += (': index 0 has length {}; index {} has length {}').format(
|
332 |
+
*details
|
333 |
+
)
|
334 |
+
|
335 |
+
super().__init__(msg)
|
336 |
+
|
337 |
+
|
338 |
+
def _zip_equal_generator(iterables):
|
339 |
+
for combo in zip_longest(*iterables, fillvalue=_marker):
|
340 |
+
for val in combo:
|
341 |
+
if val is _marker:
|
342 |
+
raise UnequalIterablesError()
|
343 |
+
yield combo
|
344 |
+
|
345 |
+
|
346 |
+
def _zip_equal(*iterables):
|
347 |
+
# Check whether the iterables are all the same size.
|
348 |
+
try:
|
349 |
+
first_size = len(iterables[0])
|
350 |
+
for i, it in enumerate(iterables[1:], 1):
|
351 |
+
size = len(it)
|
352 |
+
if size != first_size:
|
353 |
+
raise UnequalIterablesError(details=(first_size, i, size))
|
354 |
+
# All sizes are equal, we can use the built-in zip.
|
355 |
+
return zip(*iterables)
|
356 |
+
# If any one of the iterables didn't have a length, start reading
|
357 |
+
# them until one runs out.
|
358 |
+
except TypeError:
|
359 |
+
return _zip_equal_generator(iterables)
|
360 |
+
|
361 |
+
|
362 |
+
def grouper(iterable, n, incomplete='fill', fillvalue=None):
|
363 |
+
"""Group elements from *iterable* into fixed-length groups of length *n*.
|
364 |
+
|
365 |
+
>>> list(grouper('ABCDEF', 3))
|
366 |
+
[('A', 'B', 'C'), ('D', 'E', 'F')]
|
367 |
+
|
368 |
+
The keyword arguments *incomplete* and *fillvalue* control what happens for
|
369 |
+
iterables whose length is not a multiple of *n*.
|
370 |
+
|
371 |
+
When *incomplete* is `'fill'`, the last group will contain instances of
|
372 |
+
*fillvalue*.
|
373 |
+
|
374 |
+
>>> list(grouper('ABCDEFG', 3, incomplete='fill', fillvalue='x'))
|
375 |
+
[('A', 'B', 'C'), ('D', 'E', 'F'), ('G', 'x', 'x')]
|
376 |
+
|
377 |
+
When *incomplete* is `'ignore'`, the last group will not be emitted.
|
378 |
+
|
379 |
+
>>> list(grouper('ABCDEFG', 3, incomplete='ignore', fillvalue='x'))
|
380 |
+
[('A', 'B', 'C'), ('D', 'E', 'F')]
|
381 |
+
|
382 |
+
When *incomplete* is `'strict'`, a subclass of `ValueError` will be raised.
|
383 |
+
|
384 |
+
>>> it = grouper('ABCDEFG', 3, incomplete='strict')
|
385 |
+
>>> list(it) # doctest: +IGNORE_EXCEPTION_DETAIL
|
386 |
+
Traceback (most recent call last):
|
387 |
+
...
|
388 |
+
UnequalIterablesError
|
389 |
+
|
390 |
+
"""
|
391 |
+
args = [iter(iterable)] * n
|
392 |
+
if incomplete == 'fill':
|
393 |
+
return zip_longest(*args, fillvalue=fillvalue)
|
394 |
+
if incomplete == 'strict':
|
395 |
+
return _zip_equal(*args)
|
396 |
+
if incomplete == 'ignore':
|
397 |
+
return zip(*args)
|
398 |
+
else:
|
399 |
+
raise ValueError('Expected fill, strict, or ignore')
|
400 |
+
|
401 |
+
|
402 |
+
def roundrobin(*iterables):
|
403 |
+
"""Yields an item from each iterable, alternating between them.
|
404 |
+
|
405 |
+
>>> list(roundrobin('ABC', 'D', 'EF'))
|
406 |
+
['A', 'D', 'E', 'B', 'F', 'C']
|
407 |
+
|
408 |
+
This function produces the same output as :func:`interleave_longest`, but
|
409 |
+
may perform better for some inputs (in particular when the number of
|
410 |
+
iterables is small).
|
411 |
+
|
412 |
+
"""
|
413 |
+
# Recipe credited to George Sakkis
|
414 |
+
pending = len(iterables)
|
415 |
+
nexts = cycle(iter(it).__next__ for it in iterables)
|
416 |
+
while pending:
|
417 |
+
try:
|
418 |
+
for next in nexts:
|
419 |
+
yield next()
|
420 |
+
except StopIteration:
|
421 |
+
pending -= 1
|
422 |
+
nexts = cycle(islice(nexts, pending))
|
423 |
+
|
424 |
+
|
425 |
+
def partition(pred, iterable):
|
426 |
+
"""
|
427 |
+
Returns a 2-tuple of iterables derived from the input iterable.
|
428 |
+
The first yields the items that have ``pred(item) == False``.
|
429 |
+
The second yields the items that have ``pred(item) == True``.
|
430 |
+
|
431 |
+
>>> is_odd = lambda x: x % 2 != 0
|
432 |
+
>>> iterable = range(10)
|
433 |
+
>>> even_items, odd_items = partition(is_odd, iterable)
|
434 |
+
>>> list(even_items), list(odd_items)
|
435 |
+
([0, 2, 4, 6, 8], [1, 3, 5, 7, 9])
|
436 |
+
|
437 |
+
If *pred* is None, :func:`bool` is used.
|
438 |
+
|
439 |
+
>>> iterable = [0, 1, False, True, '', ' ']
|
440 |
+
>>> false_items, true_items = partition(None, iterable)
|
441 |
+
>>> list(false_items), list(true_items)
|
442 |
+
([0, False, ''], [1, True, ' '])
|
443 |
+
|
444 |
+
"""
|
445 |
+
if pred is None:
|
446 |
+
pred = bool
|
447 |
+
|
448 |
+
t1, t2, p = tee(iterable, 3)
|
449 |
+
p1, p2 = tee(map(pred, p))
|
450 |
+
return (compress(t1, map(operator.not_, p1)), compress(t2, p2))
|
451 |
+
|
452 |
+
|
453 |
+
def powerset(iterable):
|
454 |
+
"""Yields all possible subsets of the iterable.
|
455 |
+
|
456 |
+
>>> list(powerset([1, 2, 3]))
|
457 |
+
[(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
|
458 |
+
|
459 |
+
:func:`powerset` will operate on iterables that aren't :class:`set`
|
460 |
+
instances, so repeated elements in the input will produce repeated elements
|
461 |
+
in the output. Use :func:`unique_everseen` on the input to avoid generating
|
462 |
+
duplicates:
|
463 |
+
|
464 |
+
>>> seq = [1, 1, 0]
|
465 |
+
>>> list(powerset(seq))
|
466 |
+
[(), (1,), (1,), (0,), (1, 1), (1, 0), (1, 0), (1, 1, 0)]
|
467 |
+
>>> from more_itertools import unique_everseen
|
468 |
+
>>> list(powerset(unique_everseen(seq)))
|
469 |
+
[(), (1,), (0,), (1, 0)]
|
470 |
+
|
471 |
+
"""
|
472 |
+
s = list(iterable)
|
473 |
+
return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1))
|
474 |
+
|
475 |
+
|
476 |
+
def unique_everseen(iterable, key=None):
|
477 |
+
"""
|
478 |
+
Yield unique elements, preserving order.
|
479 |
+
|
480 |
+
>>> list(unique_everseen('AAAABBBCCDAABBB'))
|
481 |
+
['A', 'B', 'C', 'D']
|
482 |
+
>>> list(unique_everseen('ABBCcAD', str.lower))
|
483 |
+
['A', 'B', 'C', 'D']
|
484 |
+
|
485 |
+
Sequences with a mix of hashable and unhashable items can be used.
|
486 |
+
The function will be slower (i.e., `O(n^2)`) for unhashable items.
|
487 |
+
|
488 |
+
Remember that ``list`` objects are unhashable - you can use the *key*
|
489 |
+
parameter to transform the list to a tuple (which is hashable) to
|
490 |
+
avoid a slowdown.
|
491 |
+
|
492 |
+
>>> iterable = ([1, 2], [2, 3], [1, 2])
|
493 |
+
>>> list(unique_everseen(iterable)) # Slow
|
494 |
+
[[1, 2], [2, 3]]
|
495 |
+
>>> list(unique_everseen(iterable, key=tuple)) # Faster
|
496 |
+
[[1, 2], [2, 3]]
|
497 |
+
|
498 |
+
Similarly, you may want to convert unhashable ``set`` objects with
|
499 |
+
``key=frozenset``. For ``dict`` objects,
|
500 |
+
``key=lambda x: frozenset(x.items())`` can be used.
|
501 |
+
|
502 |
+
"""
|
503 |
+
seenset = set()
|
504 |
+
seenset_add = seenset.add
|
505 |
+
seenlist = []
|
506 |
+
seenlist_add = seenlist.append
|
507 |
+
use_key = key is not None
|
508 |
+
|
509 |
+
for element in iterable:
|
510 |
+
k = key(element) if use_key else element
|
511 |
+
try:
|
512 |
+
if k not in seenset:
|
513 |
+
seenset_add(k)
|
514 |
+
yield element
|
515 |
+
except TypeError:
|
516 |
+
if k not in seenlist:
|
517 |
+
seenlist_add(k)
|
518 |
+
yield element
|
519 |
+
|
520 |
+
|
521 |
+
def unique_justseen(iterable, key=None):
|
522 |
+
"""Yields elements in order, ignoring serial duplicates
|
523 |
+
|
524 |
+
>>> list(unique_justseen('AAAABBBCCDAABBB'))
|
525 |
+
['A', 'B', 'C', 'D', 'A', 'B']
|
526 |
+
>>> list(unique_justseen('ABBCcAD', str.lower))
|
527 |
+
['A', 'B', 'C', 'A', 'D']
|
528 |
+
|
529 |
+
"""
|
530 |
+
if key is None:
|
531 |
+
return map(operator.itemgetter(0), groupby(iterable))
|
532 |
+
|
533 |
+
return map(next, map(operator.itemgetter(1), groupby(iterable, key)))
|
534 |
+
|
535 |
+
|
536 |
+
def iter_except(func, exception, first=None):
|
537 |
+
"""Yields results from a function repeatedly until an exception is raised.
|
538 |
+
|
539 |
+
Converts a call-until-exception interface to an iterator interface.
|
540 |
+
Like ``iter(func, sentinel)``, but uses an exception instead of a sentinel
|
541 |
+
to end the loop.
|
542 |
+
|
543 |
+
>>> l = [0, 1, 2]
|
544 |
+
>>> list(iter_except(l.pop, IndexError))
|
545 |
+
[2, 1, 0]
|
546 |
+
|
547 |
+
Multiple exceptions can be specified as a stopping condition:
|
548 |
+
|
549 |
+
>>> l = [1, 2, 3, '...', 4, 5, 6]
|
550 |
+
>>> list(iter_except(lambda: 1 + l.pop(), (IndexError, TypeError)))
|
551 |
+
[7, 6, 5]
|
552 |
+
>>> list(iter_except(lambda: 1 + l.pop(), (IndexError, TypeError)))
|
553 |
+
[4, 3, 2]
|
554 |
+
>>> list(iter_except(lambda: 1 + l.pop(), (IndexError, TypeError)))
|
555 |
+
[]
|
556 |
+
|
557 |
+
"""
|
558 |
+
try:
|
559 |
+
if first is not None:
|
560 |
+
yield first()
|
561 |
+
while 1:
|
562 |
+
yield func()
|
563 |
+
except exception:
|
564 |
+
pass
|
565 |
+
|
566 |
+
|
567 |
+
def first_true(iterable, default=None, pred=None):
|
568 |
+
"""
|
569 |
+
Returns the first true value in the iterable.
|
570 |
+
|
571 |
+
If no true value is found, returns *default*
|
572 |
+
|
573 |
+
If *pred* is not None, returns the first item for which
|
574 |
+
``pred(item) == True`` .
|
575 |
+
|
576 |
+
>>> first_true(range(10))
|
577 |
+
1
|
578 |
+
>>> first_true(range(10), pred=lambda x: x > 5)
|
579 |
+
6
|
580 |
+
>>> first_true(range(10), default='missing', pred=lambda x: x > 9)
|
581 |
+
'missing'
|
582 |
+
|
583 |
+
"""
|
584 |
+
return next(filter(pred, iterable), default)
|
585 |
+
|
586 |
+
|
587 |
+
def random_product(*args, repeat=1):
|
588 |
+
"""Draw an item at random from each of the input iterables.
|
589 |
+
|
590 |
+
>>> random_product('abc', range(4), 'XYZ') # doctest:+SKIP
|
591 |
+
('c', 3, 'Z')
|
592 |
+
|
593 |
+
If *repeat* is provided as a keyword argument, that many items will be
|
594 |
+
drawn from each iterable.
|
595 |
+
|
596 |
+
>>> random_product('abcd', range(4), repeat=2) # doctest:+SKIP
|
597 |
+
('a', 2, 'd', 3)
|
598 |
+
|
599 |
+
This equivalent to taking a random selection from
|
600 |
+
``itertools.product(*args, **kwarg)``.
|
601 |
+
|
602 |
+
"""
|
603 |
+
pools = [tuple(pool) for pool in args] * repeat
|
604 |
+
return tuple(choice(pool) for pool in pools)
|
605 |
+
|
606 |
+
|
607 |
+
def random_permutation(iterable, r=None):
|
608 |
+
"""Return a random *r* length permutation of the elements in *iterable*.
|
609 |
+
|
610 |
+
If *r* is not specified or is ``None``, then *r* defaults to the length of
|
611 |
+
*iterable*.
|
612 |
+
|
613 |
+
>>> random_permutation(range(5)) # doctest:+SKIP
|
614 |
+
(3, 4, 0, 1, 2)
|
615 |
+
|
616 |
+
This equivalent to taking a random selection from
|
617 |
+
``itertools.permutations(iterable, r)``.
|
618 |
+
|
619 |
+
"""
|
620 |
+
pool = tuple(iterable)
|
621 |
+
r = len(pool) if r is None else r
|
622 |
+
return tuple(sample(pool, r))
|
623 |
+
|
624 |
+
|
625 |
+
def random_combination(iterable, r):
|
626 |
+
"""Return a random *r* length subsequence of the elements in *iterable*.
|
627 |
+
|
628 |
+
>>> random_combination(range(5), 3) # doctest:+SKIP
|
629 |
+
(2, 3, 4)
|
630 |
+
|
631 |
+
This equivalent to taking a random selection from
|
632 |
+
``itertools.combinations(iterable, r)``.
|
633 |
+
|
634 |
+
"""
|
635 |
+
pool = tuple(iterable)
|
636 |
+
n = len(pool)
|
637 |
+
indices = sorted(sample(range(n), r))
|
638 |
+
return tuple(pool[i] for i in indices)
|
639 |
+
|
640 |
+
|
641 |
+
def random_combination_with_replacement(iterable, r):
|
642 |
+
"""Return a random *r* length subsequence of elements in *iterable*,
|
643 |
+
allowing individual elements to be repeated.
|
644 |
+
|
645 |
+
>>> random_combination_with_replacement(range(3), 5) # doctest:+SKIP
|
646 |
+
(0, 0, 1, 2, 2)
|
647 |
+
|
648 |
+
This equivalent to taking a random selection from
|
649 |
+
``itertools.combinations_with_replacement(iterable, r)``.
|
650 |
+
|
651 |
+
"""
|
652 |
+
pool = tuple(iterable)
|
653 |
+
n = len(pool)
|
654 |
+
indices = sorted(randrange(n) for i in range(r))
|
655 |
+
return tuple(pool[i] for i in indices)
|
656 |
+
|
657 |
+
|
658 |
+
def nth_combination(iterable, r, index):
|
659 |
+
"""Equivalent to ``list(combinations(iterable, r))[index]``.
|
660 |
+
|
661 |
+
The subsequences of *iterable* that are of length *r* can be ordered
|
662 |
+
lexicographically. :func:`nth_combination` computes the subsequence at
|
663 |
+
sort position *index* directly, without computing the previous
|
664 |
+
subsequences.
|
665 |
+
|
666 |
+
>>> nth_combination(range(5), 3, 5)
|
667 |
+
(0, 3, 4)
|
668 |
+
|
669 |
+
``ValueError`` will be raised If *r* is negative or greater than the length
|
670 |
+
of *iterable*.
|
671 |
+
``IndexError`` will be raised if the given *index* is invalid.
|
672 |
+
"""
|
673 |
+
pool = tuple(iterable)
|
674 |
+
n = len(pool)
|
675 |
+
if (r < 0) or (r > n):
|
676 |
+
raise ValueError
|
677 |
+
|
678 |
+
c = 1
|
679 |
+
k = min(r, n - r)
|
680 |
+
for i in range(1, k + 1):
|
681 |
+
c = c * (n - k + i) // i
|
682 |
+
|
683 |
+
if index < 0:
|
684 |
+
index += c
|
685 |
+
|
686 |
+
if (index < 0) or (index >= c):
|
687 |
+
raise IndexError
|
688 |
+
|
689 |
+
result = []
|
690 |
+
while r:
|
691 |
+
c, n, r = c * r // n, n - 1, r - 1
|
692 |
+
while index >= c:
|
693 |
+
index -= c
|
694 |
+
c, n = c * (n - r) // n, n - 1
|
695 |
+
result.append(pool[-1 - n])
|
696 |
+
|
697 |
+
return tuple(result)
|
698 |
+
|
699 |
+
|
700 |
+
def prepend(value, iterator):
|
701 |
+
"""Yield *value*, followed by the elements in *iterator*.
|
702 |
+
|
703 |
+
>>> value = '0'
|
704 |
+
>>> iterator = ['1', '2', '3']
|
705 |
+
>>> list(prepend(value, iterator))
|
706 |
+
['0', '1', '2', '3']
|
707 |
+
|
708 |
+
To prepend multiple values, see :func:`itertools.chain`
|
709 |
+
or :func:`value_chain`.
|
710 |
+
|
711 |
+
"""
|
712 |
+
return chain([value], iterator)
|
713 |
+
|
714 |
+
|
715 |
+
def convolve(signal, kernel):
|
716 |
+
"""Convolve the iterable *signal* with the iterable *kernel*.
|
717 |
+
|
718 |
+
>>> signal = (1, 2, 3, 4, 5)
|
719 |
+
>>> kernel = [3, 2, 1]
|
720 |
+
>>> list(convolve(signal, kernel))
|
721 |
+
[3, 8, 14, 20, 26, 14, 5]
|
722 |
+
|
723 |
+
Note: the input arguments are not interchangeable, as the *kernel*
|
724 |
+
is immediately consumed and stored.
|
725 |
+
|
726 |
+
"""
|
727 |
+
# This implementation intentionally doesn't match the one in the itertools
|
728 |
+
# documentation.
|
729 |
+
kernel = tuple(kernel)[::-1]
|
730 |
+
n = len(kernel)
|
731 |
+
window = deque([0], maxlen=n) * n
|
732 |
+
for x in chain(signal, repeat(0, n - 1)):
|
733 |
+
window.append(x)
|
734 |
+
yield _sumprod(kernel, window)
|
735 |
+
|
736 |
+
|
737 |
+
def before_and_after(predicate, it):
|
738 |
+
"""A variant of :func:`takewhile` that allows complete access to the
|
739 |
+
remainder of the iterator.
|
740 |
+
|
741 |
+
>>> it = iter('ABCdEfGhI')
|
742 |
+
>>> all_upper, remainder = before_and_after(str.isupper, it)
|
743 |
+
>>> ''.join(all_upper)
|
744 |
+
'ABC'
|
745 |
+
>>> ''.join(remainder) # takewhile() would lose the 'd'
|
746 |
+
'dEfGhI'
|
747 |
+
|
748 |
+
Note that the first iterator must be fully consumed before the second
|
749 |
+
iterator can generate valid results.
|
750 |
+
"""
|
751 |
+
it = iter(it)
|
752 |
+
transition = []
|
753 |
+
|
754 |
+
def true_iterator():
|
755 |
+
for elem in it:
|
756 |
+
if predicate(elem):
|
757 |
+
yield elem
|
758 |
+
else:
|
759 |
+
transition.append(elem)
|
760 |
+
return
|
761 |
+
|
762 |
+
# Note: this is different from itertools recipes to allow nesting
|
763 |
+
# before_and_after remainders into before_and_after again. See tests
|
764 |
+
# for an example.
|
765 |
+
remainder_iterator = chain(transition, it)
|
766 |
+
|
767 |
+
return true_iterator(), remainder_iterator
|
768 |
+
|
769 |
+
|
770 |
+
def triplewise(iterable):
|
771 |
+
"""Return overlapping triplets from *iterable*.
|
772 |
+
|
773 |
+
>>> list(triplewise('ABCDE'))
|
774 |
+
[('A', 'B', 'C'), ('B', 'C', 'D'), ('C', 'D', 'E')]
|
775 |
+
|
776 |
+
"""
|
777 |
+
for (a, _), (b, c) in pairwise(pairwise(iterable)):
|
778 |
+
yield a, b, c
|
779 |
+
|
780 |
+
|
781 |
+
def sliding_window(iterable, n):
|
782 |
+
"""Return a sliding window of width *n* over *iterable*.
|
783 |
+
|
784 |
+
>>> list(sliding_window(range(6), 4))
|
785 |
+
[(0, 1, 2, 3), (1, 2, 3, 4), (2, 3, 4, 5)]
|
786 |
+
|
787 |
+
If *iterable* has fewer than *n* items, then nothing is yielded:
|
788 |
+
|
789 |
+
>>> list(sliding_window(range(3), 4))
|
790 |
+
[]
|
791 |
+
|
792 |
+
For a variant with more features, see :func:`windowed`.
|
793 |
+
"""
|
794 |
+
it = iter(iterable)
|
795 |
+
window = deque(islice(it, n - 1), maxlen=n)
|
796 |
+
for x in it:
|
797 |
+
window.append(x)
|
798 |
+
yield tuple(window)
|
799 |
+
|
800 |
+
|
801 |
+
def subslices(iterable):
|
802 |
+
"""Return all contiguous non-empty subslices of *iterable*.
|
803 |
+
|
804 |
+
>>> list(subslices('ABC'))
|
805 |
+
[['A'], ['A', 'B'], ['A', 'B', 'C'], ['B'], ['B', 'C'], ['C']]
|
806 |
+
|
807 |
+
This is similar to :func:`substrings`, but emits items in a different
|
808 |
+
order.
|
809 |
+
"""
|
810 |
+
seq = list(iterable)
|
811 |
+
slices = starmap(slice, combinations(range(len(seq) + 1), 2))
|
812 |
+
return map(operator.getitem, repeat(seq), slices)
|
813 |
+
|
814 |
+
|
815 |
+
def polynomial_from_roots(roots):
|
816 |
+
"""Compute a polynomial's coefficients from its roots.
|
817 |
+
|
818 |
+
>>> roots = [5, -4, 3] # (x - 5) * (x + 4) * (x - 3)
|
819 |
+
>>> polynomial_from_roots(roots) # x^3 - 4 * x^2 - 17 * x + 60
|
820 |
+
[1, -4, -17, 60]
|
821 |
+
"""
|
822 |
+
factors = zip(repeat(1), map(operator.neg, roots))
|
823 |
+
return list(reduce(convolve, factors, [1]))
|
824 |
+
|
825 |
+
|
826 |
+
def iter_index(iterable, value, start=0, stop=None):
|
827 |
+
"""Yield the index of each place in *iterable* that *value* occurs,
|
828 |
+
beginning with index *start* and ending before index *stop*.
|
829 |
+
|
830 |
+
See :func:`locate` for a more general means of finding the indexes
|
831 |
+
associated with particular values.
|
832 |
+
|
833 |
+
>>> list(iter_index('AABCADEAF', 'A'))
|
834 |
+
[0, 1, 4, 7]
|
835 |
+
>>> list(iter_index('AABCADEAF', 'A', 1)) # start index is inclusive
|
836 |
+
[1, 4, 7]
|
837 |
+
>>> list(iter_index('AABCADEAF', 'A', 1, 7)) # stop index is not inclusive
|
838 |
+
[1, 4]
|
839 |
+
"""
|
840 |
+
seq_index = getattr(iterable, 'index', None)
|
841 |
+
if seq_index is None:
|
842 |
+
# Slow path for general iterables
|
843 |
+
it = islice(iterable, start, stop)
|
844 |
+
for i, element in enumerate(it, start):
|
845 |
+
if element is value or element == value:
|
846 |
+
yield i
|
847 |
+
else:
|
848 |
+
# Fast path for sequences
|
849 |
+
stop = len(iterable) if stop is None else stop
|
850 |
+
i = start - 1
|
851 |
+
try:
|
852 |
+
while True:
|
853 |
+
yield (i := seq_index(value, i + 1, stop))
|
854 |
+
except ValueError:
|
855 |
+
pass
|
856 |
+
|
857 |
+
|
858 |
+
def sieve(n):
|
859 |
+
"""Yield the primes less than n.
|
860 |
+
|
861 |
+
>>> list(sieve(30))
|
862 |
+
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
|
863 |
+
"""
|
864 |
+
if n > 2:
|
865 |
+
yield 2
|
866 |
+
start = 3
|
867 |
+
data = bytearray((0, 1)) * (n // 2)
|
868 |
+
limit = math.isqrt(n) + 1
|
869 |
+
for p in iter_index(data, 1, start, limit):
|
870 |
+
yield from iter_index(data, 1, start, p * p)
|
871 |
+
data[p * p : n : p + p] = bytes(len(range(p * p, n, p + p)))
|
872 |
+
start = p * p
|
873 |
+
yield from iter_index(data, 1, start)
|
874 |
+
|
875 |
+
|
876 |
+
def _batched(iterable, n, *, strict=False):
|
877 |
+
"""Batch data into tuples of length *n*. If the number of items in
|
878 |
+
*iterable* is not divisible by *n*:
|
879 |
+
* The last batch will be shorter if *strict* is ``False``.
|
880 |
+
* :exc:`ValueError` will be raised if *strict* is ``True``.
|
881 |
+
|
882 |
+
>>> list(batched('ABCDEFG', 3))
|
883 |
+
[('A', 'B', 'C'), ('D', 'E', 'F'), ('G',)]
|
884 |
+
|
885 |
+
On Python 3.13 and above, this is an alias for :func:`itertools.batched`.
|
886 |
+
"""
|
887 |
+
if n < 1:
|
888 |
+
raise ValueError('n must be at least one')
|
889 |
+
it = iter(iterable)
|
890 |
+
while batch := tuple(islice(it, n)):
|
891 |
+
if strict and len(batch) != n:
|
892 |
+
raise ValueError('batched(): incomplete batch')
|
893 |
+
yield batch
|
894 |
+
|
895 |
+
|
896 |
+
if hexversion >= 0x30D00A2:
|
897 |
+
from itertools import batched as itertools_batched
|
898 |
+
|
899 |
+
def batched(iterable, n, *, strict=False):
|
900 |
+
return itertools_batched(iterable, n, strict=strict)
|
901 |
+
|
902 |
+
else:
|
903 |
+
batched = _batched
|
904 |
+
|
905 |
+
batched.__doc__ = _batched.__doc__
|
906 |
+
|
907 |
+
|
908 |
+
def transpose(it):
|
909 |
+
"""Swap the rows and columns of the input matrix.
|
910 |
+
|
911 |
+
>>> list(transpose([(1, 2, 3), (11, 22, 33)]))
|
912 |
+
[(1, 11), (2, 22), (3, 33)]
|
913 |
+
|
914 |
+
The caller should ensure that the dimensions of the input are compatible.
|
915 |
+
If the input is empty, no output will be produced.
|
916 |
+
"""
|
917 |
+
return _zip_strict(*it)
|
918 |
+
|
919 |
+
|
920 |
+
def reshape(matrix, cols):
|
921 |
+
"""Reshape the 2-D input *matrix* to have a column count given by *cols*.
|
922 |
+
|
923 |
+
>>> matrix = [(0, 1), (2, 3), (4, 5)]
|
924 |
+
>>> cols = 3
|
925 |
+
>>> list(reshape(matrix, cols))
|
926 |
+
[(0, 1, 2), (3, 4, 5)]
|
927 |
+
"""
|
928 |
+
return batched(chain.from_iterable(matrix), cols)
|
929 |
+
|
930 |
+
|
931 |
+
def matmul(m1, m2):
|
932 |
+
"""Multiply two matrices.
|
933 |
+
|
934 |
+
>>> list(matmul([(7, 5), (3, 5)], [(2, 5), (7, 9)]))
|
935 |
+
[(49, 80), (41, 60)]
|
936 |
+
|
937 |
+
The caller should ensure that the dimensions of the input matrices are
|
938 |
+
compatible with each other.
|
939 |
+
"""
|
940 |
+
n = len(m2[0])
|
941 |
+
return batched(starmap(_sumprod, product(m1, transpose(m2))), n)
|
942 |
+
|
943 |
+
|
944 |
+
def factor(n):
|
945 |
+
"""Yield the prime factors of n.
|
946 |
+
|
947 |
+
>>> list(factor(360))
|
948 |
+
[2, 2, 2, 3, 3, 5]
|
949 |
+
"""
|
950 |
+
for prime in sieve(math.isqrt(n) + 1):
|
951 |
+
while not n % prime:
|
952 |
+
yield prime
|
953 |
+
n //= prime
|
954 |
+
if n == 1:
|
955 |
+
return
|
956 |
+
if n > 1:
|
957 |
+
yield n
|
958 |
+
|
959 |
+
|
960 |
+
def polynomial_eval(coefficients, x):
|
961 |
+
"""Evaluate a polynomial at a specific value.
|
962 |
+
|
963 |
+
Example: evaluating x^3 - 4 * x^2 - 17 * x + 60 at x = 2.5:
|
964 |
+
|
965 |
+
>>> coefficients = [1, -4, -17, 60]
|
966 |
+
>>> x = 2.5
|
967 |
+
>>> polynomial_eval(coefficients, x)
|
968 |
+
8.125
|
969 |
+
"""
|
970 |
+
n = len(coefficients)
|
971 |
+
if n == 0:
|
972 |
+
return x * 0 # coerce zero to the type of x
|
973 |
+
powers = map(pow, repeat(x), reversed(range(n)))
|
974 |
+
return _sumprod(coefficients, powers)
|
975 |
+
|
976 |
+
|
977 |
+
def sum_of_squares(it):
|
978 |
+
"""Return the sum of the squares of the input values.
|
979 |
+
|
980 |
+
>>> sum_of_squares([10, 20, 30])
|
981 |
+
1400
|
982 |
+
"""
|
983 |
+
return _sumprod(*tee(it))
|
984 |
+
|
985 |
+
|
986 |
+
def polynomial_derivative(coefficients):
|
987 |
+
"""Compute the first derivative of a polynomial.
|
988 |
+
|
989 |
+
Example: evaluating the derivative of x^3 - 4 * x^2 - 17 * x + 60
|
990 |
+
|
991 |
+
>>> coefficients = [1, -4, -17, 60]
|
992 |
+
>>> derivative_coefficients = polynomial_derivative(coefficients)
|
993 |
+
>>> derivative_coefficients
|
994 |
+
[3, -8, -17]
|
995 |
+
"""
|
996 |
+
n = len(coefficients)
|
997 |
+
powers = reversed(range(1, n))
|
998 |
+
return list(map(operator.mul, coefficients, powers))
|
999 |
+
|
1000 |
+
|
1001 |
+
def totient(n):
|
1002 |
+
"""Return the count of natural numbers up to *n* that are coprime with *n*.
|
1003 |
+
|
1004 |
+
>>> totient(9)
|
1005 |
+
6
|
1006 |
+
>>> totient(12)
|
1007 |
+
4
|
1008 |
+
"""
|
1009 |
+
for p in unique_justseen(factor(n)):
|
1010 |
+
n = n // p * (p - 1)
|
1011 |
+
|
1012 |
+
return n
|
llmeval-env/lib/python3.10/site-packages/more_itertools/recipes.pyi
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Stubs for more_itertools.recipes"""
|
2 |
+
from __future__ import annotations
|
3 |
+
|
4 |
+
from typing import (
|
5 |
+
Any,
|
6 |
+
Callable,
|
7 |
+
Iterable,
|
8 |
+
Iterator,
|
9 |
+
overload,
|
10 |
+
Sequence,
|
11 |
+
Type,
|
12 |
+
TypeVar,
|
13 |
+
)
|
14 |
+
|
15 |
+
# Type and type variable definitions
|
16 |
+
_T = TypeVar('_T')
|
17 |
+
_T1 = TypeVar('_T1')
|
18 |
+
_T2 = TypeVar('_T2')
|
19 |
+
_U = TypeVar('_U')
|
20 |
+
|
21 |
+
def take(n: int, iterable: Iterable[_T]) -> list[_T]: ...
|
22 |
+
def tabulate(
|
23 |
+
function: Callable[[int], _T], start: int = ...
|
24 |
+
) -> Iterator[_T]: ...
|
25 |
+
def tail(n: int, iterable: Iterable[_T]) -> Iterator[_T]: ...
|
26 |
+
def consume(iterator: Iterable[_T], n: int | None = ...) -> None: ...
|
27 |
+
@overload
|
28 |
+
def nth(iterable: Iterable[_T], n: int) -> _T | None: ...
|
29 |
+
@overload
|
30 |
+
def nth(iterable: Iterable[_T], n: int, default: _U) -> _T | _U: ...
|
31 |
+
def all_equal(iterable: Iterable[_T]) -> bool: ...
|
32 |
+
def quantify(
|
33 |
+
iterable: Iterable[_T], pred: Callable[[_T], bool] = ...
|
34 |
+
) -> int: ...
|
35 |
+
def pad_none(iterable: Iterable[_T]) -> Iterator[_T | None]: ...
|
36 |
+
def padnone(iterable: Iterable[_T]) -> Iterator[_T | None]: ...
|
37 |
+
def ncycles(iterable: Iterable[_T], n: int) -> Iterator[_T]: ...
|
38 |
+
def dotproduct(vec1: Iterable[_T1], vec2: Iterable[_T2]) -> Any: ...
|
39 |
+
def flatten(listOfLists: Iterable[Iterable[_T]]) -> Iterator[_T]: ...
|
40 |
+
def repeatfunc(
|
41 |
+
func: Callable[..., _U], times: int | None = ..., *args: Any
|
42 |
+
) -> Iterator[_U]: ...
|
43 |
+
def pairwise(iterable: Iterable[_T]) -> Iterator[tuple[_T, _T]]: ...
|
44 |
+
def grouper(
|
45 |
+
iterable: Iterable[_T],
|
46 |
+
n: int,
|
47 |
+
incomplete: str = ...,
|
48 |
+
fillvalue: _U = ...,
|
49 |
+
) -> Iterator[tuple[_T | _U, ...]]: ...
|
50 |
+
def roundrobin(*iterables: Iterable[_T]) -> Iterator[_T]: ...
|
51 |
+
def partition(
|
52 |
+
pred: Callable[[_T], object] | None, iterable: Iterable[_T]
|
53 |
+
) -> tuple[Iterator[_T], Iterator[_T]]: ...
|
54 |
+
def powerset(iterable: Iterable[_T]) -> Iterator[tuple[_T, ...]]: ...
|
55 |
+
def unique_everseen(
|
56 |
+
iterable: Iterable[_T], key: Callable[[_T], _U] | None = ...
|
57 |
+
) -> Iterator[_T]: ...
|
58 |
+
def unique_justseen(
|
59 |
+
iterable: Iterable[_T], key: Callable[[_T], object] | None = ...
|
60 |
+
) -> Iterator[_T]: ...
|
61 |
+
@overload
|
62 |
+
def iter_except(
|
63 |
+
func: Callable[[], _T],
|
64 |
+
exception: Type[BaseException] | tuple[Type[BaseException], ...],
|
65 |
+
first: None = ...,
|
66 |
+
) -> Iterator[_T]: ...
|
67 |
+
@overload
|
68 |
+
def iter_except(
|
69 |
+
func: Callable[[], _T],
|
70 |
+
exception: Type[BaseException] | tuple[Type[BaseException], ...],
|
71 |
+
first: Callable[[], _U],
|
72 |
+
) -> Iterator[_T | _U]: ...
|
73 |
+
@overload
|
74 |
+
def first_true(
|
75 |
+
iterable: Iterable[_T], *, pred: Callable[[_T], object] | None = ...
|
76 |
+
) -> _T | None: ...
|
77 |
+
@overload
|
78 |
+
def first_true(
|
79 |
+
iterable: Iterable[_T],
|
80 |
+
default: _U,
|
81 |
+
pred: Callable[[_T], object] | None = ...,
|
82 |
+
) -> _T | _U: ...
|
83 |
+
def random_product(
|
84 |
+
*args: Iterable[_T], repeat: int = ...
|
85 |
+
) -> tuple[_T, ...]: ...
|
86 |
+
def random_permutation(
|
87 |
+
iterable: Iterable[_T], r: int | None = ...
|
88 |
+
) -> tuple[_T, ...]: ...
|
89 |
+
def random_combination(iterable: Iterable[_T], r: int) -> tuple[_T, ...]: ...
|
90 |
+
def random_combination_with_replacement(
|
91 |
+
iterable: Iterable[_T], r: int
|
92 |
+
) -> tuple[_T, ...]: ...
|
93 |
+
def nth_combination(
|
94 |
+
iterable: Iterable[_T], r: int, index: int
|
95 |
+
) -> tuple[_T, ...]: ...
|
96 |
+
def prepend(value: _T, iterator: Iterable[_U]) -> Iterator[_T | _U]: ...
|
97 |
+
def convolve(signal: Iterable[_T], kernel: Iterable[_T]) -> Iterator[_T]: ...
|
98 |
+
def before_and_after(
|
99 |
+
predicate: Callable[[_T], bool], it: Iterable[_T]
|
100 |
+
) -> tuple[Iterator[_T], Iterator[_T]]: ...
|
101 |
+
def triplewise(iterable: Iterable[_T]) -> Iterator[tuple[_T, _T, _T]]: ...
|
102 |
+
def sliding_window(
|
103 |
+
iterable: Iterable[_T], n: int
|
104 |
+
) -> Iterator[tuple[_T, ...]]: ...
|
105 |
+
def subslices(iterable: Iterable[_T]) -> Iterator[list[_T]]: ...
|
106 |
+
def polynomial_from_roots(roots: Sequence[_T]) -> list[_T]: ...
|
107 |
+
def iter_index(
|
108 |
+
iterable: Iterable[_T],
|
109 |
+
value: Any,
|
110 |
+
start: int | None = ...,
|
111 |
+
stop: int | None = ...,
|
112 |
+
) -> Iterator[int]: ...
|
113 |
+
def sieve(n: int) -> Iterator[int]: ...
|
114 |
+
def batched(
|
115 |
+
iterable: Iterable[_T], n: int, *, strict: bool = False
|
116 |
+
) -> Iterator[tuple[_T]]: ...
|
117 |
+
def transpose(
|
118 |
+
it: Iterable[Iterable[_T]],
|
119 |
+
) -> Iterator[tuple[_T, ...]]: ...
|
120 |
+
def reshape(
|
121 |
+
matrix: Iterable[Iterable[_T]], cols: int
|
122 |
+
) -> Iterator[tuple[_T, ...]]: ...
|
123 |
+
def matmul(m1: Sequence[_T], m2: Sequence[_T]) -> Iterator[tuple[_T]]: ...
|
124 |
+
def factor(n: int) -> Iterator[int]: ...
|
125 |
+
def polynomial_eval(coefficients: Sequence[_T], x: _U) -> _U: ...
|
126 |
+
def sum_of_squares(it: Iterable[_T]) -> _T: ...
|
127 |
+
def polynomial_derivative(coefficients: Sequence[_T]) -> list[_T]: ...
|
128 |
+
def totient(n: int) -> int: ...
|