ZTWHHH commited on
Commit
ed18c1e
·
verified ·
1 Parent(s): fd43201

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +2 -0
  2. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/__pycache__/__init__.cpython-310.pyc +0 -0
  3. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/__pycache__/_staggered.cpython-310.pyc +0 -0
  4. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/__pycache__/impl.cpython-310.pyc +0 -0
  5. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/__pycache__/types.cpython-310.pyc +0 -0
  6. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/__pycache__/utils.cpython-310.pyc +0 -0
  7. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/_staggered.py +202 -0
  8. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp-3.11.9.dist-info/INSTALLER +1 -0
  9. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp-3.11.9.dist-info/METADATA +250 -0
  10. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp-3.11.9.dist-info/WHEEL +6 -0
  11. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/_websocket/mask.cpython-310-x86_64-linux-gnu.so +3 -0
  12. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/_websocket/reader_c.cpython-310-x86_64-linux-gnu.so +3 -0
  13. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/INSTALLER +1 -0
  14. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/LICENSE +201 -0
  15. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/METADATA +128 -0
  16. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/RECORD +10 -0
  17. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/WHEEL +5 -0
  18. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/top_level.txt +1 -0
  19. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__init__.py +103 -0
  20. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__init__.pyi +388 -0
  21. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/__init__.cpython-310.pyc +0 -0
  22. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_cmp.cpython-310.pyc +0 -0
  23. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_compat.cpython-310.pyc +0 -0
  24. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_config.cpython-310.pyc +0 -0
  25. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_funcs.cpython-310.pyc +0 -0
  26. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_make.cpython-310.pyc +0 -0
  27. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_next_gen.cpython-310.pyc +0 -0
  28. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_version_info.cpython-310.pyc +0 -0
  29. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/converters.cpython-310.pyc +0 -0
  30. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/exceptions.cpython-310.pyc +0 -0
  31. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/filters.cpython-310.pyc +0 -0
  32. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/setters.cpython-310.pyc +0 -0
  33. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/validators.cpython-310.pyc +0 -0
  34. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_cmp.py +160 -0
  35. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_cmp.pyi +13 -0
  36. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_compat.py +103 -0
  37. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_config.py +31 -0
  38. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_funcs.py +522 -0
  39. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_make.py +2960 -0
  40. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_next_gen.py +631 -0
  41. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_typing_compat.pyi +15 -0
  42. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_version_info.py +86 -0
  43. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_version_info.pyi +9 -0
  44. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/converters.py +151 -0
  45. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/converters.pyi +13 -0
  46. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/exceptions.py +95 -0
  47. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/exceptions.pyi +17 -0
  48. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/filters.py +72 -0
  49. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/filters.pyi +6 -0
  50. vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/py.typed +0 -0
.gitattributes CHANGED
@@ -1467,3 +1467,5 @@ parrot/lib/python3.10/site-packages/sklearn/_loss/_loss.cpython-310-x86_64-linux
1467
  vllm/lib/python3.10/site-packages/ray/jars/ray_dist.jar filter=lfs diff=lfs merge=lfs -text
1468
  parrot/lib/python3.10/site-packages/pandas/_libs/tslibs/offsets.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1469
  vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/_http_writer.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
 
1467
  vllm/lib/python3.10/site-packages/ray/jars/ray_dist.jar filter=lfs diff=lfs merge=lfs -text
1468
  parrot/lib/python3.10/site-packages/pandas/_libs/tslibs/offsets.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1469
  vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/_http_writer.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1470
+ vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/_websocket/reader_c.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1471
+ vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/_websocket/mask.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (481 Bytes). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/__pycache__/_staggered.cpython-310.pyc ADDED
Binary file (5.51 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/__pycache__/impl.cpython-310.pyc ADDED
Binary file (5.59 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/__pycache__/types.cpython-310.pyc ADDED
Binary file (430 Bytes). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/__pycache__/utils.cpython-310.pyc ADDED
Binary file (2.57 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohappyeyeballs/_staggered.py ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import contextlib
3
+ from typing import (
4
+ TYPE_CHECKING,
5
+ Any,
6
+ Awaitable,
7
+ Callable,
8
+ Iterable,
9
+ List,
10
+ Optional,
11
+ Set,
12
+ Tuple,
13
+ TypeVar,
14
+ Union,
15
+ )
16
+
17
+ _T = TypeVar("_T")
18
+
19
+
20
+ def _set_result(wait_next: "asyncio.Future[None]") -> None:
21
+ """Set the result of a future if it is not already done."""
22
+ if not wait_next.done():
23
+ wait_next.set_result(None)
24
+
25
+
26
+ async def _wait_one(
27
+ futures: "Iterable[asyncio.Future[Any]]",
28
+ loop: asyncio.AbstractEventLoop,
29
+ ) -> _T:
30
+ """Wait for the first future to complete."""
31
+ wait_next = loop.create_future()
32
+
33
+ def _on_completion(fut: "asyncio.Future[Any]") -> None:
34
+ if not wait_next.done():
35
+ wait_next.set_result(fut)
36
+
37
+ for f in futures:
38
+ f.add_done_callback(_on_completion)
39
+
40
+ try:
41
+ return await wait_next
42
+ finally:
43
+ for f in futures:
44
+ f.remove_done_callback(_on_completion)
45
+
46
+
47
+ async def staggered_race(
48
+ coro_fns: Iterable[Callable[[], Awaitable[_T]]],
49
+ delay: Optional[float],
50
+ *,
51
+ loop: Optional[asyncio.AbstractEventLoop] = None,
52
+ ) -> Tuple[Optional[_T], Optional[int], List[Optional[BaseException]]]:
53
+ """
54
+ Run coroutines with staggered start times and take the first to finish.
55
+
56
+ This method takes an iterable of coroutine functions. The first one is
57
+ started immediately. From then on, whenever the immediately preceding one
58
+ fails (raises an exception), or when *delay* seconds has passed, the next
59
+ coroutine is started. This continues until one of the coroutines complete
60
+ successfully, in which case all others are cancelled, or until all
61
+ coroutines fail.
62
+
63
+ The coroutines provided should be well-behaved in the following way:
64
+
65
+ * They should only ``return`` if completed successfully.
66
+
67
+ * They should always raise an exception if they did not complete
68
+ successfully. In particular, if they handle cancellation, they should
69
+ probably reraise, like this::
70
+
71
+ try:
72
+ # do work
73
+ except asyncio.CancelledError:
74
+ # undo partially completed work
75
+ raise
76
+
77
+ Args:
78
+ ----
79
+ coro_fns: an iterable of coroutine functions, i.e. callables that
80
+ return a coroutine object when called. Use ``functools.partial`` or
81
+ lambdas to pass arguments.
82
+
83
+ delay: amount of time, in seconds, between starting coroutines. If
84
+ ``None``, the coroutines will run sequentially.
85
+
86
+ loop: the event loop to use. If ``None``, the running loop is used.
87
+
88
+ Returns:
89
+ -------
90
+ tuple *(winner_result, winner_index, exceptions)* where
91
+
92
+ - *winner_result*: the result of the winning coroutine, or ``None``
93
+ if no coroutines won.
94
+
95
+ - *winner_index*: the index of the winning coroutine in
96
+ ``coro_fns``, or ``None`` if no coroutines won. If the winning
97
+ coroutine may return None on success, *winner_index* can be used
98
+ to definitively determine whether any coroutine won.
99
+
100
+ - *exceptions*: list of exceptions returned by the coroutines.
101
+ ``len(exceptions)`` is equal to the number of coroutines actually
102
+ started, and the order is the same as in ``coro_fns``. The winning
103
+ coroutine's entry is ``None``.
104
+
105
+ """
106
+ loop = loop or asyncio.get_running_loop()
107
+ exceptions: List[Optional[BaseException]] = []
108
+ tasks: Set[asyncio.Task[Optional[Tuple[_T, int]]]] = set()
109
+
110
+ async def run_one_coro(
111
+ coro_fn: Callable[[], Awaitable[_T]],
112
+ this_index: int,
113
+ start_next: "asyncio.Future[None]",
114
+ ) -> Optional[Tuple[_T, int]]:
115
+ """
116
+ Run a single coroutine.
117
+
118
+ If the coroutine fails, set the exception in the exceptions list and
119
+ start the next coroutine by setting the result of the start_next.
120
+
121
+ If the coroutine succeeds, return the result and the index of the
122
+ coroutine in the coro_fns list.
123
+
124
+ If SystemExit or KeyboardInterrupt is raised, re-raise it.
125
+ """
126
+ try:
127
+ result = await coro_fn()
128
+ except (SystemExit, KeyboardInterrupt):
129
+ raise
130
+ except BaseException as e:
131
+ exceptions[this_index] = e
132
+ _set_result(start_next) # Kickstart the next coroutine
133
+ return None
134
+
135
+ return result, this_index
136
+
137
+ start_next_timer: Optional[asyncio.TimerHandle] = None
138
+ start_next: Optional[asyncio.Future[None]]
139
+ task: asyncio.Task[Optional[Tuple[_T, int]]]
140
+ done: Union[asyncio.Future[None], asyncio.Task[Optional[Tuple[_T, int]]]]
141
+ coro_iter = iter(coro_fns)
142
+ this_index = -1
143
+ try:
144
+ while True:
145
+ if coro_fn := next(coro_iter, None):
146
+ this_index += 1
147
+ exceptions.append(None)
148
+ start_next = loop.create_future()
149
+ task = loop.create_task(run_one_coro(coro_fn, this_index, start_next))
150
+ tasks.add(task)
151
+ start_next_timer = (
152
+ loop.call_later(delay, _set_result, start_next) if delay else None
153
+ )
154
+ elif not tasks:
155
+ # We exhausted the coro_fns list and no tasks are running
156
+ # so we have no winner and all coroutines failed.
157
+ break
158
+
159
+ while tasks:
160
+ done = await _wait_one(
161
+ [*tasks, start_next] if start_next else tasks, loop
162
+ )
163
+ if done is start_next:
164
+ # The current task has failed or the timer has expired
165
+ # so we need to start the next task.
166
+ start_next = None
167
+ if start_next_timer:
168
+ start_next_timer.cancel()
169
+ start_next_timer = None
170
+
171
+ # Break out of the task waiting loop to start the next
172
+ # task.
173
+ break
174
+
175
+ if TYPE_CHECKING:
176
+ assert isinstance(done, asyncio.Task)
177
+
178
+ tasks.remove(done)
179
+ if winner := done.result():
180
+ return *winner, exceptions
181
+ finally:
182
+ # We either have:
183
+ # - a winner
184
+ # - all tasks failed
185
+ # - a KeyboardInterrupt or SystemExit.
186
+
187
+ #
188
+ # If the timer is still running, cancel it.
189
+ #
190
+ if start_next_timer:
191
+ start_next_timer.cancel()
192
+
193
+ #
194
+ # If there are any tasks left, cancel them and than
195
+ # wait them so they fill the exceptions list.
196
+ #
197
+ for task in tasks:
198
+ task.cancel()
199
+ with contextlib.suppress(asyncio.CancelledError):
200
+ await task
201
+
202
+ return None, None, exceptions
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp-3.11.9.dist-info/INSTALLER ADDED
@@ -0,0 +1 @@
 
 
1
+ pip
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp-3.11.9.dist-info/METADATA ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: aiohttp
3
+ Version: 3.11.9
4
+ Summary: Async http client/server framework (asyncio)
5
+ Home-page: https://github.com/aio-libs/aiohttp
6
+ Maintainer: aiohttp team <team@aiohttp.org>
7
+ Maintainer-email: team@aiohttp.org
8
+ License: Apache-2.0
9
+ Project-URL: Chat: Matrix, https://matrix.to/#/#aio-libs:matrix.org
10
+ Project-URL: Chat: Matrix Space, https://matrix.to/#/#aio-libs-space:matrix.org
11
+ Project-URL: CI: GitHub Actions, https://github.com/aio-libs/aiohttp/actions?query=workflow%3ACI
12
+ Project-URL: Coverage: codecov, https://codecov.io/github/aio-libs/aiohttp
13
+ Project-URL: Docs: Changelog, https://docs.aiohttp.org/en/stable/changes.html
14
+ Project-URL: Docs: RTD, https://docs.aiohttp.org
15
+ Project-URL: GitHub: issues, https://github.com/aio-libs/aiohttp/issues
16
+ Project-URL: GitHub: repo, https://github.com/aio-libs/aiohttp
17
+ Classifier: Development Status :: 5 - Production/Stable
18
+ Classifier: Framework :: AsyncIO
19
+ Classifier: Intended Audience :: Developers
20
+ Classifier: License :: OSI Approved :: Apache Software License
21
+ Classifier: Operating System :: POSIX
22
+ Classifier: Operating System :: MacOS :: MacOS X
23
+ Classifier: Operating System :: Microsoft :: Windows
24
+ Classifier: Programming Language :: Python
25
+ Classifier: Programming Language :: Python :: 3
26
+ Classifier: Programming Language :: Python :: 3.9
27
+ Classifier: Programming Language :: Python :: 3.10
28
+ Classifier: Programming Language :: Python :: 3.11
29
+ Classifier: Programming Language :: Python :: 3.12
30
+ Classifier: Programming Language :: Python :: 3.13
31
+ Classifier: Topic :: Internet :: WWW/HTTP
32
+ Requires-Python: >=3.9
33
+ Description-Content-Type: text/x-rst
34
+ License-File: LICENSE.txt
35
+ Requires-Dist: aiohappyeyeballs>=2.3.0
36
+ Requires-Dist: aiosignal>=1.1.2
37
+ Requires-Dist: async-timeout<6.0,>=4.0; python_version < "3.11"
38
+ Requires-Dist: attrs>=17.3.0
39
+ Requires-Dist: frozenlist>=1.1.1
40
+ Requires-Dist: multidict<7.0,>=4.5
41
+ Requires-Dist: propcache>=0.2.0
42
+ Requires-Dist: yarl<2.0,>=1.17.0
43
+ Provides-Extra: speedups
44
+ Requires-Dist: aiodns>=3.2.0; (sys_platform == "linux" or sys_platform == "darwin") and extra == "speedups"
45
+ Requires-Dist: Brotli; platform_python_implementation == "CPython" and extra == "speedups"
46
+ Requires-Dist: brotlicffi; platform_python_implementation != "CPython" and extra == "speedups"
47
+
48
+ ==================================
49
+ Async http client/server framework
50
+ ==================================
51
+
52
+ .. image:: https://raw.githubusercontent.com/aio-libs/aiohttp/master/docs/aiohttp-plain.svg
53
+ :height: 64px
54
+ :width: 64px
55
+ :alt: aiohttp logo
56
+
57
+ |
58
+
59
+ .. image:: https://github.com/aio-libs/aiohttp/workflows/CI/badge.svg
60
+ :target: https://github.com/aio-libs/aiohttp/actions?query=workflow%3ACI
61
+ :alt: GitHub Actions status for master branch
62
+
63
+ .. image:: https://codecov.io/gh/aio-libs/aiohttp/branch/master/graph/badge.svg
64
+ :target: https://codecov.io/gh/aio-libs/aiohttp
65
+ :alt: codecov.io status for master branch
66
+
67
+ .. image:: https://img.shields.io/endpoint?url=https://codspeed.io/badge.json
68
+ :target: https://codspeed.io/aio-libs/aiohttp
69
+ :alt: Codspeed.io status for aiohttp
70
+
71
+ .. image:: https://badge.fury.io/py/aiohttp.svg
72
+ :target: https://pypi.org/project/aiohttp
73
+ :alt: Latest PyPI package version
74
+
75
+ .. image:: https://readthedocs.org/projects/aiohttp/badge/?version=latest
76
+ :target: https://docs.aiohttp.org/
77
+ :alt: Latest Read The Docs
78
+
79
+ .. image:: https://img.shields.io/matrix/aio-libs:matrix.org?label=Discuss%20on%20Matrix%20at%20%23aio-libs%3Amatrix.org&logo=matrix&server_fqdn=matrix.org&style=flat
80
+ :target: https://matrix.to/#/%23aio-libs:matrix.org
81
+ :alt: Matrix Room — #aio-libs:matrix.org
82
+
83
+ .. image:: https://img.shields.io/matrix/aio-libs-space:matrix.org?label=Discuss%20on%20Matrix%20at%20%23aio-libs-space%3Amatrix.org&logo=matrix&server_fqdn=matrix.org&style=flat
84
+ :target: https://matrix.to/#/%23aio-libs-space:matrix.org
85
+ :alt: Matrix Space — #aio-libs-space:matrix.org
86
+
87
+
88
+ Key Features
89
+ ============
90
+
91
+ - Supports both client and server side of HTTP protocol.
92
+ - Supports both client and server Web-Sockets out-of-the-box and avoids
93
+ Callback Hell.
94
+ - Provides Web-server with middleware and pluggable routing.
95
+
96
+
97
+ Getting started
98
+ ===============
99
+
100
+ Client
101
+ ------
102
+
103
+ To get something from the web:
104
+
105
+ .. code-block:: python
106
+
107
+ import aiohttp
108
+ import asyncio
109
+
110
+ async def main():
111
+
112
+ async with aiohttp.ClientSession() as session:
113
+ async with session.get('http://python.org') as response:
114
+
115
+ print("Status:", response.status)
116
+ print("Content-type:", response.headers['content-type'])
117
+
118
+ html = await response.text()
119
+ print("Body:", html[:15], "...")
120
+
121
+ asyncio.run(main())
122
+
123
+ This prints:
124
+
125
+ .. code-block::
126
+
127
+ Status: 200
128
+ Content-type: text/html; charset=utf-8
129
+ Body: <!doctype html> ...
130
+
131
+ Coming from `requests <https://requests.readthedocs.io/>`_ ? Read `why we need so many lines <https://aiohttp.readthedocs.io/en/latest/http_request_lifecycle.html>`_.
132
+
133
+ Server
134
+ ------
135
+
136
+ An example using a simple server:
137
+
138
+ .. code-block:: python
139
+
140
+ # examples/server_simple.py
141
+ from aiohttp import web
142
+
143
+ async def handle(request):
144
+ name = request.match_info.get('name', "Anonymous")
145
+ text = "Hello, " + name
146
+ return web.Response(text=text)
147
+
148
+ async def wshandle(request):
149
+ ws = web.WebSocketResponse()
150
+ await ws.prepare(request)
151
+
152
+ async for msg in ws:
153
+ if msg.type == web.WSMsgType.text:
154
+ await ws.send_str("Hello, {}".format(msg.data))
155
+ elif msg.type == web.WSMsgType.binary:
156
+ await ws.send_bytes(msg.data)
157
+ elif msg.type == web.WSMsgType.close:
158
+ break
159
+
160
+ return ws
161
+
162
+
163
+ app = web.Application()
164
+ app.add_routes([web.get('/', handle),
165
+ web.get('/echo', wshandle),
166
+ web.get('/{name}', handle)])
167
+
168
+ if __name__ == '__main__':
169
+ web.run_app(app)
170
+
171
+
172
+ Documentation
173
+ =============
174
+
175
+ https://aiohttp.readthedocs.io/
176
+
177
+
178
+ Demos
179
+ =====
180
+
181
+ https://github.com/aio-libs/aiohttp-demos
182
+
183
+
184
+ External links
185
+ ==============
186
+
187
+ * `Third party libraries
188
+ <http://aiohttp.readthedocs.io/en/latest/third_party.html>`_
189
+ * `Built with aiohttp
190
+ <http://aiohttp.readthedocs.io/en/latest/built_with.html>`_
191
+ * `Powered by aiohttp
192
+ <http://aiohttp.readthedocs.io/en/latest/powered_by.html>`_
193
+
194
+ Feel free to make a Pull Request for adding your link to these pages!
195
+
196
+
197
+ Communication channels
198
+ ======================
199
+
200
+ *aio-libs Discussions*: https://github.com/aio-libs/aiohttp/discussions
201
+
202
+ *Matrix*: `#aio-libs:matrix.org <https://matrix.to/#/#aio-libs:matrix.org>`_
203
+
204
+ We support `Stack Overflow
205
+ <https://stackoverflow.com/questions/tagged/aiohttp>`_.
206
+ Please add *aiohttp* tag to your question there.
207
+
208
+ Requirements
209
+ ============
210
+
211
+ - attrs_
212
+ - multidict_
213
+ - yarl_
214
+ - frozenlist_
215
+
216
+ Optionally you may install the aiodns_ library (highly recommended for sake of speed).
217
+
218
+ .. _aiodns: https://pypi.python.org/pypi/aiodns
219
+ .. _attrs: https://github.com/python-attrs/attrs
220
+ .. _multidict: https://pypi.python.org/pypi/multidict
221
+ .. _frozenlist: https://pypi.org/project/frozenlist/
222
+ .. _yarl: https://pypi.python.org/pypi/yarl
223
+ .. _async-timeout: https://pypi.python.org/pypi/async_timeout
224
+
225
+ License
226
+ =======
227
+
228
+ ``aiohttp`` is offered under the Apache 2 license.
229
+
230
+
231
+ Keepsafe
232
+ ========
233
+
234
+ The aiohttp community would like to thank Keepsafe
235
+ (https://www.getkeepsafe.com) for its support in the early days of
236
+ the project.
237
+
238
+
239
+ Source code
240
+ ===========
241
+
242
+ The latest developer version is available in a GitHub repository:
243
+ https://github.com/aio-libs/aiohttp
244
+
245
+ Benchmarks
246
+ ==========
247
+
248
+ If you are interested in efficiency, the AsyncIO community maintains a
249
+ list of benchmarks on the official wiki:
250
+ https://github.com/python/asyncio/wiki/Benchmarks
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp-3.11.9.dist-info/WHEEL ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.6.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp310-cp310-manylinux_2_17_x86_64
5
+ Tag: cp310-cp310-manylinux2014_x86_64
6
+
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/_websocket/mask.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2fd6a3b37ac599df64623caa2d945ddccd5a6f7f5807d42b03d7394256e4ed6d
3
+ size 223824
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/_websocket/reader_c.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c5ee8930e058192e5010d0bf82618fce110b123c08a7ca5db16bbb7fe1af988
3
+ size 1666456
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/INSTALLER ADDED
@@ -0,0 +1 @@
 
 
1
+ pip
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2013-2019 Nikolay Kim and Andrew Svetlov
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/METADATA ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: aiosignal
3
+ Version: 1.3.1
4
+ Summary: aiosignal: a list of registered asynchronous callbacks
5
+ Home-page: https://github.com/aio-libs/aiosignal
6
+ Maintainer: aiohttp team <team@aiohttp.org>
7
+ Maintainer-email: team@aiohttp.org
8
+ License: Apache 2.0
9
+ Project-URL: Chat: Gitter, https://gitter.im/aio-libs/Lobby
10
+ Project-URL: CI: GitHub Actions, https://github.com/aio-libs/aiosignal/actions
11
+ Project-URL: Coverage: codecov, https://codecov.io/github/aio-libs/aiosignal
12
+ Project-URL: Docs: RTD, https://docs.aiosignal.org
13
+ Project-URL: GitHub: issues, https://github.com/aio-libs/aiosignal/issues
14
+ Project-URL: GitHub: repo, https://github.com/aio-libs/aiosignal
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Programming Language :: Python
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.7
21
+ Classifier: Programming Language :: Python :: 3.8
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Development Status :: 5 - Production/Stable
26
+ Classifier: Operating System :: POSIX
27
+ Classifier: Operating System :: MacOS :: MacOS X
28
+ Classifier: Operating System :: Microsoft :: Windows
29
+ Classifier: Framework :: AsyncIO
30
+ Requires-Python: >=3.7
31
+ Description-Content-Type: text/x-rst
32
+ License-File: LICENSE
33
+ Requires-Dist: frozenlist (>=1.1.0)
34
+
35
+ =========
36
+ aiosignal
37
+ =========
38
+
39
+ .. image:: https://github.com/aio-libs/aiosignal/workflows/CI/badge.svg
40
+ :target: https://github.com/aio-libs/aiosignal/actions?query=workflow%3ACI
41
+ :alt: GitHub status for master branch
42
+
43
+ .. image:: https://codecov.io/gh/aio-libs/aiosignal/branch/master/graph/badge.svg
44
+ :target: https://codecov.io/gh/aio-libs/aiosignal
45
+ :alt: codecov.io status for master branch
46
+
47
+ .. image:: https://badge.fury.io/py/aiosignal.svg
48
+ :target: https://pypi.org/project/aiosignal
49
+ :alt: Latest PyPI package version
50
+
51
+ .. image:: https://readthedocs.org/projects/aiosignal/badge/?version=latest
52
+ :target: https://aiosignal.readthedocs.io/
53
+ :alt: Latest Read The Docs
54
+
55
+ .. image:: https://img.shields.io/discourse/topics?server=https%3A%2F%2Faio-libs.discourse.group%2F
56
+ :target: https://aio-libs.discourse.group/
57
+ :alt: Discourse group for io-libs
58
+
59
+ .. image:: https://badges.gitter.im/Join%20Chat.svg
60
+ :target: https://gitter.im/aio-libs/Lobby
61
+ :alt: Chat on Gitter
62
+
63
+ Introduction
64
+ ============
65
+
66
+ A project to manage callbacks in `asyncio` projects.
67
+
68
+ ``Signal`` is a list of registered asynchronous callbacks.
69
+
70
+ The signal's life-cycle has two stages: after creation its content
71
+ could be filled by using standard list operations: ``sig.append()``
72
+ etc.
73
+
74
+ After you call ``sig.freeze()`` the signal is *frozen*: adding, removing
75
+ and dropping callbacks is forbidden.
76
+
77
+ The only available operation is calling the previously registered
78
+ callbacks by using ``await sig.send(data)``.
79
+
80
+ For concrete usage examples see the `Signals
81
+ <https://docs.aiohttp.org/en/stable/web_advanced.html#aiohttp-web-signals>
82
+ section of the `Web Server Advanced
83
+ <https://docs.aiohttp.org/en/stable/web_advanced.html>` chapter of the `aiohttp
84
+ documentation`_.
85
+
86
+
87
+ Installation
88
+ ------------
89
+
90
+ ::
91
+
92
+ $ pip install aiosignal
93
+
94
+ The library requires Python 3.6 or newer.
95
+
96
+
97
+ Documentation
98
+ =============
99
+
100
+ https://aiosignal.readthedocs.io/
101
+
102
+ Communication channels
103
+ ======================
104
+
105
+ *gitter chat* https://gitter.im/aio-libs/Lobby
106
+
107
+ Requirements
108
+ ============
109
+
110
+ - Python >= 3.6
111
+ - frozenlist >= 1.0.0
112
+
113
+ License
114
+ =======
115
+
116
+ ``aiosignal`` is offered under the Apache 2 license.
117
+
118
+ Source code
119
+ ===========
120
+
121
+ The project is hosted on GitHub_
122
+
123
+ Please file an issue in the `bug tracker
124
+ <https://github.com/aio-libs/aiosignal/issues>`_ if you have found a bug
125
+ or have some suggestions to improve the library.
126
+
127
+ .. _GitHub: https://github.com/aio-libs/aiosignal
128
+ .. _aiohttp documentation: https://docs.aiohttp.org/
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/RECORD ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ aiosignal-1.3.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
2
+ aiosignal-1.3.1.dist-info/LICENSE,sha256=b9UkPpLdf5jsacesN3co50kFcJ_1J6W_mNbQJjwE9bY,11332
3
+ aiosignal-1.3.1.dist-info/METADATA,sha256=c0HRnlYzfXKztZPTFDlPfygizTherhG5WdwXlvco0Ug,4008
4
+ aiosignal-1.3.1.dist-info/RECORD,,
5
+ aiosignal-1.3.1.dist-info/WHEEL,sha256=ZL1lC_LiPDNRgDnOl2taCMc83aPEUZgHHv2h-LDgdiM,92
6
+ aiosignal-1.3.1.dist-info/top_level.txt,sha256=z45aNOKGDdrI1roqZY3BGXQ22kJFPHBmVdwtLYLtXC0,10
7
+ aiosignal/__init__.py,sha256=zQNfFYRSd84bswvpFv8ZWjEr5DeYwV3LXbMSyo2222s,867
8
+ aiosignal/__init__.pyi,sha256=xeCddYSS8fZAkz8S4HuKSR2IDe3N7RW_LKcXDPPA1Xk,311
9
+ aiosignal/__pycache__/__init__.cpython-310.pyc,,
10
+ aiosignal/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/WHEEL ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.38.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiosignal-1.3.1.dist-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ aiosignal
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__init__.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Converter,
19
+ Factory,
20
+ attrib,
21
+ attrs,
22
+ fields,
23
+ fields_dict,
24
+ make_class,
25
+ validate,
26
+ )
27
+ from ._next_gen import define, field, frozen, mutable
28
+ from ._version_info import VersionInfo
29
+
30
+
31
+ s = attributes = attrs
32
+ ib = attr = attrib
33
+ dataclass = partial(attrs, auto_attribs=True) # happy Easter ;)
34
+
35
+
36
+ class AttrsInstance(Protocol):
37
+ pass
38
+
39
+
40
+ __all__ = [
41
+ "Attribute",
42
+ "AttrsInstance",
43
+ "Converter",
44
+ "Factory",
45
+ "NOTHING",
46
+ "asdict",
47
+ "assoc",
48
+ "astuple",
49
+ "attr",
50
+ "attrib",
51
+ "attributes",
52
+ "attrs",
53
+ "cmp_using",
54
+ "converters",
55
+ "define",
56
+ "evolve",
57
+ "exceptions",
58
+ "field",
59
+ "fields",
60
+ "fields_dict",
61
+ "filters",
62
+ "frozen",
63
+ "get_run_validators",
64
+ "has",
65
+ "ib",
66
+ "make_class",
67
+ "mutable",
68
+ "resolve_types",
69
+ "s",
70
+ "set_run_validators",
71
+ "setters",
72
+ "validate",
73
+ "validators",
74
+ ]
75
+
76
+
77
+ def _make_getattr(mod_name: str) -> Callable:
78
+ """
79
+ Create a metadata proxy for packaging information that uses *mod_name* in
80
+ its warnings and errors.
81
+ """
82
+
83
+ def __getattr__(name: str) -> str:
84
+ if name not in ("__version__", "__version_info__"):
85
+ msg = f"module {mod_name} has no attribute {name}"
86
+ raise AttributeError(msg)
87
+
88
+ try:
89
+ from importlib.metadata import metadata
90
+ except ImportError:
91
+ from importlib_metadata import metadata
92
+
93
+ meta = metadata("attrs")
94
+
95
+ if name == "__version_info__":
96
+ return VersionInfo._from_version_string(meta["version"])
97
+
98
+ return meta["version"]
99
+
100
+ return __getattr__
101
+
102
+
103
+ __getattr__ = _make_getattr(__name__)
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__init__.pyi ADDED
@@ -0,0 +1,388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import enum
2
+ import sys
3
+
4
+ from typing import (
5
+ Any,
6
+ Callable,
7
+ Generic,
8
+ Mapping,
9
+ Protocol,
10
+ Sequence,
11
+ TypeVar,
12
+ overload,
13
+ )
14
+
15
+ # `import X as X` is required to make these public
16
+ from . import converters as converters
17
+ from . import exceptions as exceptions
18
+ from . import filters as filters
19
+ from . import setters as setters
20
+ from . import validators as validators
21
+ from ._cmp import cmp_using as cmp_using
22
+ from ._typing_compat import AttrsInstance_
23
+ from ._version_info import VersionInfo
24
+ from attrs import (
25
+ define as define,
26
+ field as field,
27
+ mutable as mutable,
28
+ frozen as frozen,
29
+ _EqOrderType,
30
+ _ValidatorType,
31
+ _ConverterType,
32
+ _ReprArgType,
33
+ _OnSetAttrType,
34
+ _OnSetAttrArgType,
35
+ _FieldTransformer,
36
+ _ValidatorArgType,
37
+ )
38
+
39
+ if sys.version_info >= (3, 10):
40
+ from typing import TypeGuard
41
+ else:
42
+ from typing_extensions import TypeGuard
43
+
44
+ if sys.version_info >= (3, 11):
45
+ from typing import dataclass_transform
46
+ else:
47
+ from typing_extensions import dataclass_transform
48
+
49
+ __version__: str
50
+ __version_info__: VersionInfo
51
+ __title__: str
52
+ __description__: str
53
+ __url__: str
54
+ __uri__: str
55
+ __author__: str
56
+ __email__: str
57
+ __license__: str
58
+ __copyright__: str
59
+
60
+ _T = TypeVar("_T")
61
+ _C = TypeVar("_C", bound=type)
62
+
63
+ _FilterType = Callable[["Attribute[_T]", _T], bool]
64
+
65
+ # We subclass this here to keep the protocol's qualified name clean.
66
+ class AttrsInstance(AttrsInstance_, Protocol):
67
+ pass
68
+
69
+ _A = TypeVar("_A", bound=type[AttrsInstance])
70
+
71
+ class _Nothing(enum.Enum):
72
+ NOTHING = enum.auto()
73
+
74
+ NOTHING = _Nothing.NOTHING
75
+
76
+ # NOTE: Factory lies about its return type to make this possible:
77
+ # `x: List[int] # = Factory(list)`
78
+ # Work around mypy issue #4554 in the common case by using an overload.
79
+ if sys.version_info >= (3, 8):
80
+ from typing import Literal
81
+ @overload
82
+ def Factory(factory: Callable[[], _T]) -> _T: ...
83
+ @overload
84
+ def Factory(
85
+ factory: Callable[[Any], _T],
86
+ takes_self: Literal[True],
87
+ ) -> _T: ...
88
+ @overload
89
+ def Factory(
90
+ factory: Callable[[], _T],
91
+ takes_self: Literal[False],
92
+ ) -> _T: ...
93
+
94
+ else:
95
+ @overload
96
+ def Factory(factory: Callable[[], _T]) -> _T: ...
97
+ @overload
98
+ def Factory(
99
+ factory: Union[Callable[[Any], _T], Callable[[], _T]],
100
+ takes_self: bool = ...,
101
+ ) -> _T: ...
102
+
103
+ In = TypeVar("In")
104
+ Out = TypeVar("Out")
105
+
106
+ class Converter(Generic[In, Out]):
107
+ @overload
108
+ def __init__(self, converter: Callable[[In], Out]) -> None: ...
109
+ @overload
110
+ def __init__(
111
+ self,
112
+ converter: Callable[[In, AttrsInstance, Attribute], Out],
113
+ *,
114
+ takes_self: Literal[True],
115
+ takes_field: Literal[True],
116
+ ) -> None: ...
117
+ @overload
118
+ def __init__(
119
+ self,
120
+ converter: Callable[[In, Attribute], Out],
121
+ *,
122
+ takes_field: Literal[True],
123
+ ) -> None: ...
124
+ @overload
125
+ def __init__(
126
+ self,
127
+ converter: Callable[[In, AttrsInstance], Out],
128
+ *,
129
+ takes_self: Literal[True],
130
+ ) -> None: ...
131
+
132
+ class Attribute(Generic[_T]):
133
+ name: str
134
+ default: _T | None
135
+ validator: _ValidatorType[_T] | None
136
+ repr: _ReprArgType
137
+ cmp: _EqOrderType
138
+ eq: _EqOrderType
139
+ order: _EqOrderType
140
+ hash: bool | None
141
+ init: bool
142
+ converter: _ConverterType | Converter[Any, _T] | None
143
+ metadata: dict[Any, Any]
144
+ type: type[_T] | None
145
+ kw_only: bool
146
+ on_setattr: _OnSetAttrType
147
+ alias: str | None
148
+
149
+ def evolve(self, **changes: Any) -> "Attribute[Any]": ...
150
+
151
+ # NOTE: We had several choices for the annotation to use for type arg:
152
+ # 1) Type[_T]
153
+ # - Pros: Handles simple cases correctly
154
+ # - Cons: Might produce less informative errors in the case of conflicting
155
+ # TypeVars e.g. `attr.ib(default='bad', type=int)`
156
+ # 2) Callable[..., _T]
157
+ # - Pros: Better error messages than #1 for conflicting TypeVars
158
+ # - Cons: Terrible error messages for validator checks.
159
+ # e.g. attr.ib(type=int, validator=validate_str)
160
+ # -> error: Cannot infer function type argument
161
+ # 3) type (and do all of the work in the mypy plugin)
162
+ # - Pros: Simple here, and we could customize the plugin with our own errors.
163
+ # - Cons: Would need to write mypy plugin code to handle all the cases.
164
+ # We chose option #1.
165
+
166
+ # `attr` lies about its return type to make the following possible:
167
+ # attr() -> Any
168
+ # attr(8) -> int
169
+ # attr(validator=<some callable>) -> Whatever the callable expects.
170
+ # This makes this type of assignments possible:
171
+ # x: int = attr(8)
172
+ #
173
+ # This form catches explicit None or no default but with no other arguments
174
+ # returns Any.
175
+ @overload
176
+ def attrib(
177
+ default: None = ...,
178
+ validator: None = ...,
179
+ repr: _ReprArgType = ...,
180
+ cmp: _EqOrderType | None = ...,
181
+ hash: bool | None = ...,
182
+ init: bool = ...,
183
+ metadata: Mapping[Any, Any] | None = ...,
184
+ type: None = ...,
185
+ converter: None = ...,
186
+ factory: None = ...,
187
+ kw_only: bool = ...,
188
+ eq: _EqOrderType | None = ...,
189
+ order: _EqOrderType | None = ...,
190
+ on_setattr: _OnSetAttrArgType | None = ...,
191
+ alias: str | None = ...,
192
+ ) -> Any: ...
193
+
194
+ # This form catches an explicit None or no default and infers the type from the
195
+ # other arguments.
196
+ @overload
197
+ def attrib(
198
+ default: None = ...,
199
+ validator: _ValidatorArgType[_T] | None = ...,
200
+ repr: _ReprArgType = ...,
201
+ cmp: _EqOrderType | None = ...,
202
+ hash: bool | None = ...,
203
+ init: bool = ...,
204
+ metadata: Mapping[Any, Any] | None = ...,
205
+ type: type[_T] | None = ...,
206
+ converter: _ConverterType | Converter[Any, _T] | None = ...,
207
+ factory: Callable[[], _T] | None = ...,
208
+ kw_only: bool = ...,
209
+ eq: _EqOrderType | None = ...,
210
+ order: _EqOrderType | None = ...,
211
+ on_setattr: _OnSetAttrArgType | None = ...,
212
+ alias: str | None = ...,
213
+ ) -> _T: ...
214
+
215
+ # This form catches an explicit default argument.
216
+ @overload
217
+ def attrib(
218
+ default: _T,
219
+ validator: _ValidatorArgType[_T] | None = ...,
220
+ repr: _ReprArgType = ...,
221
+ cmp: _EqOrderType | None = ...,
222
+ hash: bool | None = ...,
223
+ init: bool = ...,
224
+ metadata: Mapping[Any, Any] | None = ...,
225
+ type: type[_T] | None = ...,
226
+ converter: _ConverterType | Converter[Any, _T] | None = ...,
227
+ factory: Callable[[], _T] | None = ...,
228
+ kw_only: bool = ...,
229
+ eq: _EqOrderType | None = ...,
230
+ order: _EqOrderType | None = ...,
231
+ on_setattr: _OnSetAttrArgType | None = ...,
232
+ alias: str | None = ...,
233
+ ) -> _T: ...
234
+
235
+ # This form covers type=non-Type: e.g. forward references (str), Any
236
+ @overload
237
+ def attrib(
238
+ default: _T | None = ...,
239
+ validator: _ValidatorArgType[_T] | None = ...,
240
+ repr: _ReprArgType = ...,
241
+ cmp: _EqOrderType | None = ...,
242
+ hash: bool | None = ...,
243
+ init: bool = ...,
244
+ metadata: Mapping[Any, Any] | None = ...,
245
+ type: object = ...,
246
+ converter: _ConverterType | Converter[Any, _T] | None = ...,
247
+ factory: Callable[[], _T] | None = ...,
248
+ kw_only: bool = ...,
249
+ eq: _EqOrderType | None = ...,
250
+ order: _EqOrderType | None = ...,
251
+ on_setattr: _OnSetAttrArgType | None = ...,
252
+ alias: str | None = ...,
253
+ ) -> Any: ...
254
+ @overload
255
+ @dataclass_transform(order_default=True, field_specifiers=(attrib, field))
256
+ def attrs(
257
+ maybe_cls: _C,
258
+ these: dict[str, Any] | None = ...,
259
+ repr_ns: str | None = ...,
260
+ repr: bool = ...,
261
+ cmp: _EqOrderType | None = ...,
262
+ hash: bool | None = ...,
263
+ init: bool = ...,
264
+ slots: bool = ...,
265
+ frozen: bool = ...,
266
+ weakref_slot: bool = ...,
267
+ str: bool = ...,
268
+ auto_attribs: bool = ...,
269
+ kw_only: bool = ...,
270
+ cache_hash: bool = ...,
271
+ auto_exc: bool = ...,
272
+ eq: _EqOrderType | None = ...,
273
+ order: _EqOrderType | None = ...,
274
+ auto_detect: bool = ...,
275
+ collect_by_mro: bool = ...,
276
+ getstate_setstate: bool | None = ...,
277
+ on_setattr: _OnSetAttrArgType | None = ...,
278
+ field_transformer: _FieldTransformer | None = ...,
279
+ match_args: bool = ...,
280
+ unsafe_hash: bool | None = ...,
281
+ ) -> _C: ...
282
+ @overload
283
+ @dataclass_transform(order_default=True, field_specifiers=(attrib, field))
284
+ def attrs(
285
+ maybe_cls: None = ...,
286
+ these: dict[str, Any] | None = ...,
287
+ repr_ns: str | None = ...,
288
+ repr: bool = ...,
289
+ cmp: _EqOrderType | None = ...,
290
+ hash: bool | None = ...,
291
+ init: bool = ...,
292
+ slots: bool = ...,
293
+ frozen: bool = ...,
294
+ weakref_slot: bool = ...,
295
+ str: bool = ...,
296
+ auto_attribs: bool = ...,
297
+ kw_only: bool = ...,
298
+ cache_hash: bool = ...,
299
+ auto_exc: bool = ...,
300
+ eq: _EqOrderType | None = ...,
301
+ order: _EqOrderType | None = ...,
302
+ auto_detect: bool = ...,
303
+ collect_by_mro: bool = ...,
304
+ getstate_setstate: bool | None = ...,
305
+ on_setattr: _OnSetAttrArgType | None = ...,
306
+ field_transformer: _FieldTransformer | None = ...,
307
+ match_args: bool = ...,
308
+ unsafe_hash: bool | None = ...,
309
+ ) -> Callable[[_C], _C]: ...
310
+ def fields(cls: type[AttrsInstance]) -> Any: ...
311
+ def fields_dict(cls: type[AttrsInstance]) -> dict[str, Attribute[Any]]: ...
312
+ def validate(inst: AttrsInstance) -> None: ...
313
+ def resolve_types(
314
+ cls: _A,
315
+ globalns: dict[str, Any] | None = ...,
316
+ localns: dict[str, Any] | None = ...,
317
+ attribs: list[Attribute[Any]] | None = ...,
318
+ include_extras: bool = ...,
319
+ ) -> _A: ...
320
+
321
+ # TODO: add support for returning a proper attrs class from the mypy plugin
322
+ # we use Any instead of _CountingAttr so that e.g. `make_class('Foo',
323
+ # [attr.ib()])` is valid
324
+ def make_class(
325
+ name: str,
326
+ attrs: list[str] | tuple[str, ...] | dict[str, Any],
327
+ bases: tuple[type, ...] = ...,
328
+ class_body: dict[str, Any] | None = ...,
329
+ repr_ns: str | None = ...,
330
+ repr: bool = ...,
331
+ cmp: _EqOrderType | None = ...,
332
+ hash: bool | None = ...,
333
+ init: bool = ...,
334
+ slots: bool = ...,
335
+ frozen: bool = ...,
336
+ weakref_slot: bool = ...,
337
+ str: bool = ...,
338
+ auto_attribs: bool = ...,
339
+ kw_only: bool = ...,
340
+ cache_hash: bool = ...,
341
+ auto_exc: bool = ...,
342
+ eq: _EqOrderType | None = ...,
343
+ order: _EqOrderType | None = ...,
344
+ collect_by_mro: bool = ...,
345
+ on_setattr: _OnSetAttrArgType | None = ...,
346
+ field_transformer: _FieldTransformer | None = ...,
347
+ ) -> type: ...
348
+
349
+ # _funcs --
350
+
351
+ # TODO: add support for returning TypedDict from the mypy plugin
352
+ # FIXME: asdict/astuple do not honor their factory args. Waiting on one of
353
+ # these:
354
+ # https://github.com/python/mypy/issues/4236
355
+ # https://github.com/python/typing/issues/253
356
+ # XXX: remember to fix attrs.asdict/astuple too!
357
+ def asdict(
358
+ inst: AttrsInstance,
359
+ recurse: bool = ...,
360
+ filter: _FilterType[Any] | None = ...,
361
+ dict_factory: type[Mapping[Any, Any]] = ...,
362
+ retain_collection_types: bool = ...,
363
+ value_serializer: Callable[[type, Attribute[Any], Any], Any] | None = ...,
364
+ tuple_keys: bool | None = ...,
365
+ ) -> dict[str, Any]: ...
366
+
367
+ # TODO: add support for returning NamedTuple from the mypy plugin
368
+ def astuple(
369
+ inst: AttrsInstance,
370
+ recurse: bool = ...,
371
+ filter: _FilterType[Any] | None = ...,
372
+ tuple_factory: type[Sequence[Any]] = ...,
373
+ retain_collection_types: bool = ...,
374
+ ) -> tuple[Any, ...]: ...
375
+ def has(cls: type) -> TypeGuard[type[AttrsInstance]]: ...
376
+ def assoc(inst: _T, **changes: Any) -> _T: ...
377
+ def evolve(inst: _T, **changes: Any) -> _T: ...
378
+
379
+ # _config --
380
+
381
+ def set_run_validators(run: bool) -> None: ...
382
+ def get_run_validators() -> bool: ...
383
+
384
+ # aliases --
385
+
386
+ s = attributes = attrs
387
+ ib = attr = attrib
388
+ dataclass = attrs # Technically, partial(attrs, auto_attribs=True) ;)
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (2.31 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_cmp.cpython-310.pyc ADDED
Binary file (4.06 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_compat.cpython-310.pyc ADDED
Binary file (2.63 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_config.cpython-310.pyc ADDED
Binary file (1.03 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_funcs.cpython-310.pyc ADDED
Binary file (12 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_make.cpython-310.pyc ADDED
Binary file (64.1 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_next_gen.cpython-310.pyc ADDED
Binary file (23.9 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/_version_info.cpython-310.pyc ADDED
Binary file (2.35 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/converters.cpython-310.pyc ADDED
Binary file (3.54 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/exceptions.cpython-310.pyc ADDED
Binary file (3.19 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/filters.cpython-310.pyc ADDED
Binary file (2.28 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/setters.cpython-310.pyc ADDED
Binary file (1.63 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/__pycache__/validators.cpython-310.pyc ADDED
Binary file (20.3 kB). View file
 
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_cmp.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Args:
30
+ eq (typing.Callable | None):
31
+ Callable used to evaluate equality of two objects.
32
+
33
+ lt (typing.Callable | None):
34
+ Callable used to evaluate whether one object is less than another
35
+ object.
36
+
37
+ le (typing.Callable | None):
38
+ Callable used to evaluate whether one object is less than or equal
39
+ to another object.
40
+
41
+ gt (typing.Callable | None):
42
+ Callable used to evaluate whether one object is greater than
43
+ another object.
44
+
45
+ ge (typing.Callable | None):
46
+ Callable used to evaluate whether one object is greater than or
47
+ equal to another object.
48
+
49
+ require_same_type (bool):
50
+ When `True`, equality and ordering methods will return
51
+ `NotImplemented` if objects are not of the same type.
52
+
53
+ class_name (str | None): Name of class. Defaults to "Comparable".
54
+
55
+ See `comparison` for more details.
56
+
57
+ .. versionadded:: 21.1.0
58
+ """
59
+
60
+ body = {
61
+ "__slots__": ["value"],
62
+ "__init__": _make_init(),
63
+ "_requirements": [],
64
+ "_is_comparable_to": _is_comparable_to,
65
+ }
66
+
67
+ # Add operations.
68
+ num_order_functions = 0
69
+ has_eq_function = False
70
+
71
+ if eq is not None:
72
+ has_eq_function = True
73
+ body["__eq__"] = _make_operator("eq", eq)
74
+ body["__ne__"] = _make_ne()
75
+
76
+ if lt is not None:
77
+ num_order_functions += 1
78
+ body["__lt__"] = _make_operator("lt", lt)
79
+
80
+ if le is not None:
81
+ num_order_functions += 1
82
+ body["__le__"] = _make_operator("le", le)
83
+
84
+ if gt is not None:
85
+ num_order_functions += 1
86
+ body["__gt__"] = _make_operator("gt", gt)
87
+
88
+ if ge is not None:
89
+ num_order_functions += 1
90
+ body["__ge__"] = _make_operator("ge", ge)
91
+
92
+ type_ = types.new_class(
93
+ class_name, (object,), {}, lambda ns: ns.update(body)
94
+ )
95
+
96
+ # Add same type requirement.
97
+ if require_same_type:
98
+ type_._requirements.append(_check_same_type)
99
+
100
+ # Add total ordering if at least one operation was defined.
101
+ if 0 < num_order_functions < 4:
102
+ if not has_eq_function:
103
+ # functools.total_ordering requires __eq__ to be defined,
104
+ # so raise early error here to keep a nice stack.
105
+ msg = "eq must be define is order to complete ordering from lt, le, gt, ge."
106
+ raise ValueError(msg)
107
+ type_ = functools.total_ordering(type_)
108
+
109
+ return type_
110
+
111
+
112
+ def _make_init():
113
+ """
114
+ Create __init__ method.
115
+ """
116
+
117
+ def __init__(self, value):
118
+ """
119
+ Initialize object with *value*.
120
+ """
121
+ self.value = value
122
+
123
+ return __init__
124
+
125
+
126
+ def _make_operator(name, func):
127
+ """
128
+ Create operator method.
129
+ """
130
+
131
+ def method(self, other):
132
+ if not self._is_comparable_to(other):
133
+ return NotImplemented
134
+
135
+ result = func(self.value, other.value)
136
+ if result is NotImplemented:
137
+ return NotImplemented
138
+
139
+ return result
140
+
141
+ method.__name__ = f"__{name}__"
142
+ method.__doc__ = (
143
+ f"Return a {_operation_names[name]} b. Computed by attrs."
144
+ )
145
+
146
+ return method
147
+
148
+
149
+ def _is_comparable_to(self, other):
150
+ """
151
+ Check whether `other` is comparable to `self`.
152
+ """
153
+ return all(func(self, other) for func in self._requirements)
154
+
155
+
156
+ def _check_same_type(self, other):
157
+ """
158
+ Return True if *self* and *other* are of the same type, False otherwise.
159
+ """
160
+ return other.value.__class__ is self.value.__class__
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_cmp.pyi ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Callable
2
+
3
+ _CompareWithType = Callable[[Any, Any], bool]
4
+
5
+ def cmp_using(
6
+ eq: _CompareWithType | None = ...,
7
+ lt: _CompareWithType | None = ...,
8
+ le: _CompareWithType | None = ...,
9
+ gt: _CompareWithType | None = ...,
10
+ ge: _CompareWithType | None = ...,
11
+ require_same_type: bool = ...,
12
+ class_name: str = ...,
13
+ ) -> type: ...
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_compat.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ PY_3_10_PLUS = sys.version_info[:2] >= (3, 10)
16
+ PY_3_11_PLUS = sys.version_info[:2] >= (3, 11)
17
+ PY_3_12_PLUS = sys.version_info[:2] >= (3, 12)
18
+ PY_3_13_PLUS = sys.version_info[:2] >= (3, 13)
19
+ PY_3_14_PLUS = sys.version_info[:2] >= (3, 14)
20
+
21
+
22
+ if sys.version_info < (3, 8):
23
+ try:
24
+ from typing_extensions import Protocol
25
+ except ImportError: # pragma: no cover
26
+ Protocol = object
27
+ else:
28
+ from typing import Protocol # noqa: F401
29
+
30
+ if PY_3_14_PLUS: # pragma: no cover
31
+ import annotationlib
32
+
33
+ _get_annotations = annotationlib.get_annotations
34
+
35
+ else:
36
+
37
+ def _get_annotations(cls):
38
+ """
39
+ Get annotations for *cls*.
40
+ """
41
+ return cls.__dict__.get("__annotations__", {})
42
+
43
+
44
+ class _AnnotationExtractor:
45
+ """
46
+ Extract type annotations from a callable, returning None whenever there
47
+ is none.
48
+ """
49
+
50
+ __slots__ = ["sig"]
51
+
52
+ def __init__(self, callable):
53
+ try:
54
+ self.sig = inspect.signature(callable)
55
+ except (ValueError, TypeError): # inspect failed
56
+ self.sig = None
57
+
58
+ def get_first_param_type(self):
59
+ """
60
+ Return the type annotation of the first argument if it's not empty.
61
+ """
62
+ if not self.sig:
63
+ return None
64
+
65
+ params = list(self.sig.parameters.values())
66
+ if params and params[0].annotation is not inspect.Parameter.empty:
67
+ return params[0].annotation
68
+
69
+ return None
70
+
71
+ def get_return_type(self):
72
+ """
73
+ Return the return type if it's not empty.
74
+ """
75
+ if (
76
+ self.sig
77
+ and self.sig.return_annotation is not inspect.Signature.empty
78
+ ):
79
+ return self.sig.return_annotation
80
+
81
+ return None
82
+
83
+
84
+ # Thread-local global to track attrs instances which are already being repr'd.
85
+ # This is needed because there is no other (thread-safe) way to pass info
86
+ # about the instances that are already being repr'd through the call stack
87
+ # in order to ensure we don't perform infinite recursion.
88
+ #
89
+ # For instance, if an instance contains a dict which contains that instance,
90
+ # we need to know that we're already repr'ing the outside instance from within
91
+ # the dict's repr() call.
92
+ #
93
+ # This lives here rather than in _make.py so that the functions in _make.py
94
+ # don't have a direct reference to the thread-local in their globals dict.
95
+ # If they have such a reference, it breaks cloudpickle.
96
+ repr_context = threading.local()
97
+
98
+
99
+ def get_generic_base(cl):
100
+ """If this is a generic class (A[str]), return the generic base for it."""
101
+ if cl.__class__ is _GenericAlias:
102
+ return cl.__origin__
103
+ return None
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/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
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_funcs.py ADDED
@@ -0,0 +1,522 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 _OBJ_SETATTR, NOTHING, 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
+ Args:
25
+ inst: Instance of an *attrs*-decorated class.
26
+
27
+ recurse (bool): Recurse into classes that are also *attrs*-decorated.
28
+
29
+ filter (~typing.Callable):
30
+ A callable whose return code determines whether an attribute or
31
+ element is included (`True`) or dropped (`False`). Is called with
32
+ the `attrs.Attribute` as the first argument and the value as the
33
+ second argument.
34
+
35
+ dict_factory (~typing.Callable):
36
+ A callable to produce dictionaries from. For example, to produce
37
+ ordered dictionaries instead of normal Python dictionaries, pass in
38
+ ``collections.OrderedDict``.
39
+
40
+ retain_collection_types (bool):
41
+ Do not convert to `list` when encountering an attribute whose type
42
+ is `tuple` or `set`. Only meaningful if *recurse* is `True`.
43
+
44
+ value_serializer (typing.Callable | None):
45
+ A hook that is called for every attribute or dict key/value. It
46
+ receives the current instance, field and value and must return the
47
+ (updated) value. The hook is run *after* the optional *filter* has
48
+ been applied.
49
+
50
+ Returns:
51
+ Return type of *dict_factory*.
52
+
53
+ Raises:
54
+ attrs.exceptions.NotAnAttrsClassError:
55
+ If *cls* is not an *attrs* class.
56
+
57
+ .. versionadded:: 16.0.0 *dict_factory*
58
+ .. versionadded:: 16.1.0 *retain_collection_types*
59
+ .. versionadded:: 20.3.0 *value_serializer*
60
+ .. versionadded:: 21.3.0
61
+ If a dict has a collection for a key, it is serialized as a tuple.
62
+ """
63
+ attrs = fields(inst.__class__)
64
+ rv = dict_factory()
65
+ for a in attrs:
66
+ v = getattr(inst, a.name)
67
+ if filter is not None and not filter(a, v):
68
+ continue
69
+
70
+ if value_serializer is not None:
71
+ v = value_serializer(inst, a, v)
72
+
73
+ if recurse is True:
74
+ if has(v.__class__):
75
+ rv[a.name] = asdict(
76
+ v,
77
+ recurse=True,
78
+ filter=filter,
79
+ dict_factory=dict_factory,
80
+ retain_collection_types=retain_collection_types,
81
+ value_serializer=value_serializer,
82
+ )
83
+ elif isinstance(v, (tuple, list, set, frozenset)):
84
+ cf = v.__class__ if retain_collection_types is True else list
85
+ items = [
86
+ _asdict_anything(
87
+ i,
88
+ is_key=False,
89
+ filter=filter,
90
+ dict_factory=dict_factory,
91
+ retain_collection_types=retain_collection_types,
92
+ value_serializer=value_serializer,
93
+ )
94
+ for i in v
95
+ ]
96
+ try:
97
+ rv[a.name] = cf(items)
98
+ except TypeError:
99
+ if not issubclass(cf, tuple):
100
+ raise
101
+ # Workaround for TypeError: cf.__new__() missing 1 required
102
+ # positional argument (which appears, for a namedturle)
103
+ rv[a.name] = cf(*items)
104
+ elif isinstance(v, dict):
105
+ df = dict_factory
106
+ rv[a.name] = df(
107
+ (
108
+ _asdict_anything(
109
+ kk,
110
+ is_key=True,
111
+ filter=filter,
112
+ dict_factory=df,
113
+ retain_collection_types=retain_collection_types,
114
+ value_serializer=value_serializer,
115
+ ),
116
+ _asdict_anything(
117
+ vv,
118
+ is_key=False,
119
+ filter=filter,
120
+ dict_factory=df,
121
+ retain_collection_types=retain_collection_types,
122
+ value_serializer=value_serializer,
123
+ ),
124
+ )
125
+ for kk, vv in v.items()
126
+ )
127
+ else:
128
+ rv[a.name] = v
129
+ else:
130
+ rv[a.name] = v
131
+ return rv
132
+
133
+
134
+ def _asdict_anything(
135
+ val,
136
+ is_key,
137
+ filter,
138
+ dict_factory,
139
+ retain_collection_types,
140
+ value_serializer,
141
+ ):
142
+ """
143
+ ``asdict`` only works on attrs instances, this works on anything.
144
+ """
145
+ if getattr(val.__class__, "__attrs_attrs__", None) is not None:
146
+ # Attrs class.
147
+ rv = asdict(
148
+ val,
149
+ recurse=True,
150
+ filter=filter,
151
+ dict_factory=dict_factory,
152
+ retain_collection_types=retain_collection_types,
153
+ value_serializer=value_serializer,
154
+ )
155
+ elif isinstance(val, (tuple, list, set, frozenset)):
156
+ if retain_collection_types is True:
157
+ cf = val.__class__
158
+ elif is_key:
159
+ cf = tuple
160
+ else:
161
+ cf = list
162
+
163
+ rv = cf(
164
+ [
165
+ _asdict_anything(
166
+ i,
167
+ is_key=False,
168
+ filter=filter,
169
+ dict_factory=dict_factory,
170
+ retain_collection_types=retain_collection_types,
171
+ value_serializer=value_serializer,
172
+ )
173
+ for i in val
174
+ ]
175
+ )
176
+ elif isinstance(val, dict):
177
+ df = dict_factory
178
+ rv = df(
179
+ (
180
+ _asdict_anything(
181
+ kk,
182
+ is_key=True,
183
+ filter=filter,
184
+ dict_factory=df,
185
+ retain_collection_types=retain_collection_types,
186
+ value_serializer=value_serializer,
187
+ ),
188
+ _asdict_anything(
189
+ vv,
190
+ is_key=False,
191
+ filter=filter,
192
+ dict_factory=df,
193
+ retain_collection_types=retain_collection_types,
194
+ value_serializer=value_serializer,
195
+ ),
196
+ )
197
+ for kk, vv in val.items()
198
+ )
199
+ else:
200
+ rv = val
201
+ if value_serializer is not None:
202
+ rv = value_serializer(None, None, rv)
203
+
204
+ return rv
205
+
206
+
207
+ def astuple(
208
+ inst,
209
+ recurse=True,
210
+ filter=None,
211
+ tuple_factory=tuple,
212
+ retain_collection_types=False,
213
+ ):
214
+ """
215
+ Return the *attrs* attribute values of *inst* as a tuple.
216
+
217
+ Optionally recurse into other *attrs*-decorated classes.
218
+
219
+ Args:
220
+ inst: Instance of an *attrs*-decorated class.
221
+
222
+ recurse (bool):
223
+ Recurse into classes that are also *attrs*-decorated.
224
+
225
+ filter (~typing.Callable):
226
+ A callable whose return code determines whether an attribute or
227
+ element is included (`True`) or dropped (`False`). Is called with
228
+ the `attrs.Attribute` as the first argument and the value as the
229
+ second argument.
230
+
231
+ tuple_factory (~typing.Callable):
232
+ A callable to produce tuples from. For example, to produce lists
233
+ instead of tuples.
234
+
235
+ retain_collection_types (bool):
236
+ Do not convert to `list` or `dict` when encountering an attribute
237
+ which type is `tuple`, `dict` or `set`. Only meaningful if
238
+ *recurse* is `True`.
239
+
240
+ Returns:
241
+ Return type of *tuple_factory*
242
+
243
+ Raises:
244
+ attrs.exceptions.NotAnAttrsClassError:
245
+ If *cls* is not an *attrs* class.
246
+
247
+ .. versionadded:: 16.2.0
248
+ """
249
+ attrs = fields(inst.__class__)
250
+ rv = []
251
+ retain = retain_collection_types # Very long. :/
252
+ for a in attrs:
253
+ v = getattr(inst, a.name)
254
+ if filter is not None and not filter(a, v):
255
+ continue
256
+ if recurse is True:
257
+ if has(v.__class__):
258
+ rv.append(
259
+ astuple(
260
+ v,
261
+ recurse=True,
262
+ filter=filter,
263
+ tuple_factory=tuple_factory,
264
+ retain_collection_types=retain,
265
+ )
266
+ )
267
+ elif isinstance(v, (tuple, list, set, frozenset)):
268
+ cf = v.__class__ if retain is True else list
269
+ items = [
270
+ (
271
+ astuple(
272
+ j,
273
+ recurse=True,
274
+ filter=filter,
275
+ tuple_factory=tuple_factory,
276
+ retain_collection_types=retain,
277
+ )
278
+ if has(j.__class__)
279
+ else j
280
+ )
281
+ for j in v
282
+ ]
283
+ try:
284
+ rv.append(cf(items))
285
+ except TypeError:
286
+ if not issubclass(cf, tuple):
287
+ raise
288
+ # Workaround for TypeError: cf.__new__() missing 1 required
289
+ # positional argument (which appears, for a namedturle)
290
+ rv.append(cf(*items))
291
+ elif isinstance(v, dict):
292
+ df = v.__class__ if retain is True else dict
293
+ rv.append(
294
+ df(
295
+ (
296
+ (
297
+ astuple(
298
+ kk,
299
+ tuple_factory=tuple_factory,
300
+ retain_collection_types=retain,
301
+ )
302
+ if has(kk.__class__)
303
+ else kk
304
+ ),
305
+ (
306
+ astuple(
307
+ vv,
308
+ tuple_factory=tuple_factory,
309
+ retain_collection_types=retain,
310
+ )
311
+ if has(vv.__class__)
312
+ else vv
313
+ ),
314
+ )
315
+ for kk, vv in v.items()
316
+ )
317
+ )
318
+ else:
319
+ rv.append(v)
320
+ else:
321
+ rv.append(v)
322
+
323
+ return rv if tuple_factory is list else tuple_factory(rv)
324
+
325
+
326
+ def has(cls):
327
+ """
328
+ Check whether *cls* is a class with *attrs* attributes.
329
+
330
+ Args:
331
+ cls (type): Class to introspect.
332
+
333
+ Raises:
334
+ TypeError: If *cls* is not a class.
335
+
336
+ Returns:
337
+ bool:
338
+ """
339
+ attrs = getattr(cls, "__attrs_attrs__", None)
340
+ if attrs is not None:
341
+ return True
342
+
343
+ # No attrs, maybe it's a specialized generic (A[str])?
344
+ generic_base = get_generic_base(cls)
345
+ if generic_base is not None:
346
+ generic_attrs = getattr(generic_base, "__attrs_attrs__", None)
347
+ if generic_attrs is not None:
348
+ # Stick it on here for speed next time.
349
+ cls.__attrs_attrs__ = generic_attrs
350
+ return generic_attrs is not None
351
+ return False
352
+
353
+
354
+ def assoc(inst, **changes):
355
+ """
356
+ Copy *inst* and apply *changes*.
357
+
358
+ This is different from `evolve` that applies the changes to the arguments
359
+ that create the new instance.
360
+
361
+ `evolve`'s behavior is preferable, but there are `edge cases`_ where it
362
+ doesn't work. Therefore `assoc` is deprecated, but will not be removed.
363
+
364
+ .. _`edge cases`: https://github.com/python-attrs/attrs/issues/251
365
+
366
+ Args:
367
+ inst: Instance of a class with *attrs* attributes.
368
+
369
+ changes: Keyword changes in the new copy.
370
+
371
+ Returns:
372
+ A copy of inst with *changes* incorporated.
373
+
374
+ Raises:
375
+ attrs.exceptions.AttrsAttributeNotFoundError:
376
+ If *attr_name* couldn't be found on *cls*.
377
+
378
+ attrs.exceptions.NotAnAttrsClassError:
379
+ If *cls* is not an *attrs* class.
380
+
381
+ .. deprecated:: 17.1.0
382
+ Use `attrs.evolve` instead if you can. This function will not be
383
+ removed du to the slightly different approach compared to
384
+ `attrs.evolve`, though.
385
+ """
386
+ new = copy.copy(inst)
387
+ attrs = fields(inst.__class__)
388
+ for k, v in changes.items():
389
+ a = getattr(attrs, k, NOTHING)
390
+ if a is NOTHING:
391
+ msg = f"{k} is not an attrs attribute on {new.__class__}."
392
+ raise AttrsAttributeNotFoundError(msg)
393
+ _OBJ_SETATTR(new, k, v)
394
+ return new
395
+
396
+
397
+ def evolve(*args, **changes):
398
+ """
399
+ Create a new instance, based on the first positional argument with
400
+ *changes* applied.
401
+
402
+ Args:
403
+
404
+ inst:
405
+ Instance of a class with *attrs* attributes. *inst* must be passed
406
+ as a positional argument.
407
+
408
+ changes:
409
+ Keyword changes in the new copy.
410
+
411
+ Returns:
412
+ A copy of inst with *changes* incorporated.
413
+
414
+ Raises:
415
+ TypeError:
416
+ If *attr_name* couldn't be found in the class ``__init__``.
417
+
418
+ attrs.exceptions.NotAnAttrsClassError:
419
+ If *cls* is not an *attrs* class.
420
+
421
+ .. versionadded:: 17.1.0
422
+ .. deprecated:: 23.1.0
423
+ It is now deprecated to pass the instance using the keyword argument
424
+ *inst*. It will raise a warning until at least April 2024, after which
425
+ it will become an error. Always pass the instance as a positional
426
+ argument.
427
+ .. versionchanged:: 24.1.0
428
+ *inst* can't be passed as a keyword argument anymore.
429
+ """
430
+ try:
431
+ (inst,) = args
432
+ except ValueError:
433
+ msg = (
434
+ f"evolve() takes 1 positional argument, but {len(args)} were given"
435
+ )
436
+ raise TypeError(msg) from None
437
+
438
+ cls = inst.__class__
439
+ attrs = fields(cls)
440
+ for a in attrs:
441
+ if not a.init:
442
+ continue
443
+ attr_name = a.name # To deal with private attributes.
444
+ init_name = a.alias
445
+ if init_name not in changes:
446
+ changes[init_name] = getattr(inst, attr_name)
447
+
448
+ return cls(**changes)
449
+
450
+
451
+ def resolve_types(
452
+ cls, globalns=None, localns=None, attribs=None, include_extras=True
453
+ ):
454
+ """
455
+ Resolve any strings and forward annotations in type annotations.
456
+
457
+ This is only required if you need concrete types in :class:`Attribute`'s
458
+ *type* field. In other words, you don't need to resolve your types if you
459
+ only use them for static type checking.
460
+
461
+ With no arguments, names will be looked up in the module in which the class
462
+ was created. If this is not what you want, for example, if the name only
463
+ exists inside a method, you may pass *globalns* or *localns* to specify
464
+ other dictionaries in which to look up these names. See the docs of
465
+ `typing.get_type_hints` for more details.
466
+
467
+ Args:
468
+ cls (type): Class to resolve.
469
+
470
+ globalns (dict | None): Dictionary containing global variables.
471
+
472
+ localns (dict | None): Dictionary containing local variables.
473
+
474
+ attribs (list | None):
475
+ List of attribs for the given class. This is necessary when calling
476
+ from inside a ``field_transformer`` since *cls* is not an *attrs*
477
+ class yet.
478
+
479
+ include_extras (bool):
480
+ Resolve more accurately, if possible. Pass ``include_extras`` to
481
+ ``typing.get_hints``, if supported by the typing module. On
482
+ supported Python versions (3.9+), this resolves the types more
483
+ accurately.
484
+
485
+ Raises:
486
+ TypeError: If *cls* is not a class.
487
+
488
+ attrs.exceptions.NotAnAttrsClassError:
489
+ If *cls* is not an *attrs* class and you didn't pass any attribs.
490
+
491
+ NameError: If types cannot be resolved because of missing variables.
492
+
493
+ Returns:
494
+ *cls* so you can use this function also as a class decorator. Please
495
+ note that you have to apply it **after** `attrs.define`. That means the
496
+ decorator has to come in the line **before** `attrs.define`.
497
+
498
+ .. versionadded:: 20.1.0
499
+ .. versionadded:: 21.1.0 *attribs*
500
+ .. versionadded:: 23.1.0 *include_extras*
501
+ """
502
+ # Since calling get_type_hints is expensive we cache whether we've
503
+ # done it already.
504
+ if getattr(cls, "__attrs_types_resolved__", None) != cls:
505
+ import typing
506
+
507
+ kwargs = {"globalns": globalns, "localns": localns}
508
+
509
+ if PY_3_9_PLUS:
510
+ kwargs["include_extras"] = include_extras
511
+
512
+ hints = typing.get_type_hints(cls, **kwargs)
513
+ for field in fields(cls) if attribs is None else attribs:
514
+ if field.name in hints:
515
+ # Since fields have been frozen we must work around it.
516
+ _OBJ_SETATTR(field, "type", hints[field.name])
517
+ # We store the class we resolved so that subclasses know they haven't
518
+ # been resolved.
519
+ cls.__attrs_types_resolved__ = cls
520
+
521
+ # Return the class so you can use it as a decorator too.
522
+ return cls
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_make.py ADDED
@@ -0,0 +1,2960 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: MIT
2
+
3
+ from __future__ import annotations
4
+
5
+ import abc
6
+ import contextlib
7
+ import copy
8
+ import enum
9
+ import functools
10
+ import inspect
11
+ import itertools
12
+ import linecache
13
+ import sys
14
+ import types
15
+ import typing
16
+
17
+ from operator import itemgetter
18
+
19
+ # We need to import _compat itself in addition to the _compat members to avoid
20
+ # having the thread-local in the globals here.
21
+ from . import _compat, _config, setters
22
+ from ._compat import (
23
+ PY_3_8_PLUS,
24
+ PY_3_10_PLUS,
25
+ PY_3_11_PLUS,
26
+ _AnnotationExtractor,
27
+ _get_annotations,
28
+ get_generic_base,
29
+ )
30
+ from .exceptions import (
31
+ DefaultAlreadySetError,
32
+ FrozenInstanceError,
33
+ NotAnAttrsClassError,
34
+ UnannotatedAttributeError,
35
+ )
36
+
37
+
38
+ # This is used at least twice, so cache it here.
39
+ _OBJ_SETATTR = object.__setattr__
40
+ _INIT_FACTORY_PAT = "__attr_factory_%s"
41
+ _CLASSVAR_PREFIXES = (
42
+ "typing.ClassVar",
43
+ "t.ClassVar",
44
+ "ClassVar",
45
+ "typing_extensions.ClassVar",
46
+ )
47
+ # we don't use a double-underscore prefix because that triggers
48
+ # name mangling when trying to create a slot for the field
49
+ # (when slots=True)
50
+ _HASH_CACHE_FIELD = "_attrs_cached_hash"
51
+
52
+ _EMPTY_METADATA_SINGLETON = types.MappingProxyType({})
53
+
54
+ # Unique object for unequivocal getattr() defaults.
55
+ _SENTINEL = object()
56
+
57
+ _DEFAULT_ON_SETATTR = setters.pipe(setters.convert, setters.validate)
58
+
59
+
60
+ class _Nothing(enum.Enum):
61
+ """
62
+ Sentinel to indicate the lack of a value when `None` is ambiguous.
63
+
64
+ If extending attrs, you can use ``typing.Literal[NOTHING]`` to show
65
+ that a value may be ``NOTHING``.
66
+
67
+ .. versionchanged:: 21.1.0 ``bool(NOTHING)`` is now False.
68
+ .. versionchanged:: 22.2.0 ``NOTHING`` is now an ``enum.Enum`` variant.
69
+ """
70
+
71
+ NOTHING = enum.auto()
72
+
73
+ def __repr__(self):
74
+ return "NOTHING"
75
+
76
+ def __bool__(self):
77
+ return False
78
+
79
+
80
+ NOTHING = _Nothing.NOTHING
81
+ """
82
+ Sentinel to indicate the lack of a value when `None` is ambiguous.
83
+ """
84
+
85
+
86
+ class _CacheHashWrapper(int):
87
+ """
88
+ An integer subclass that pickles / copies as None
89
+
90
+ This is used for non-slots classes with ``cache_hash=True``, to avoid
91
+ serializing a potentially (even likely) invalid hash value. Since `None`
92
+ is the default value for uncalculated hashes, whenever this is copied,
93
+ the copy's value for the hash should automatically reset.
94
+
95
+ See GH #613 for more details.
96
+ """
97
+
98
+ def __reduce__(self, _none_constructor=type(None), _args=()): # noqa: B008
99
+ return _none_constructor, _args
100
+
101
+
102
+ def attrib(
103
+ default=NOTHING,
104
+ validator=None,
105
+ repr=True,
106
+ cmp=None,
107
+ hash=None,
108
+ init=True,
109
+ metadata=None,
110
+ type=None,
111
+ converter=None,
112
+ factory=None,
113
+ kw_only=False,
114
+ eq=None,
115
+ order=None,
116
+ on_setattr=None,
117
+ alias=None,
118
+ ):
119
+ """
120
+ Create a new field / attribute on a class.
121
+
122
+ Identical to `attrs.field`, except it's not keyword-only.
123
+
124
+ Consider using `attrs.field` in new code (``attr.ib`` will *never* go away,
125
+ though).
126
+
127
+ .. warning::
128
+
129
+ Does **nothing** unless the class is also decorated with
130
+ `attr.s` (or similar)!
131
+
132
+
133
+ .. versionadded:: 15.2.0 *convert*
134
+ .. versionadded:: 16.3.0 *metadata*
135
+ .. versionchanged:: 17.1.0 *validator* can be a ``list`` now.
136
+ .. versionchanged:: 17.1.0
137
+ *hash* is `None` and therefore mirrors *eq* by default.
138
+ .. versionadded:: 17.3.0 *type*
139
+ .. deprecated:: 17.4.0 *convert*
140
+ .. versionadded:: 17.4.0
141
+ *converter* as a replacement for the deprecated *convert* to achieve
142
+ consistency with other noun-based arguments.
143
+ .. versionadded:: 18.1.0
144
+ ``factory=f`` is syntactic sugar for ``default=attr.Factory(f)``.
145
+ .. versionadded:: 18.2.0 *kw_only*
146
+ .. versionchanged:: 19.2.0 *convert* keyword argument removed.
147
+ .. versionchanged:: 19.2.0 *repr* also accepts a custom callable.
148
+ .. deprecated:: 19.2.0 *cmp* Removal on or after 2021-06-01.
149
+ .. versionadded:: 19.2.0 *eq* and *order*
150
+ .. versionadded:: 20.1.0 *on_setattr*
151
+ .. versionchanged:: 20.3.0 *kw_only* backported to Python 2
152
+ .. versionchanged:: 21.1.0
153
+ *eq*, *order*, and *cmp* also accept a custom callable
154
+ .. versionchanged:: 21.1.0 *cmp* undeprecated
155
+ .. versionadded:: 22.2.0 *alias*
156
+ """
157
+ eq, eq_key, order, order_key = _determine_attrib_eq_order(
158
+ cmp, eq, order, True
159
+ )
160
+
161
+ if hash is not None and hash is not True and hash is not False:
162
+ msg = "Invalid value for hash. Must be True, False, or None."
163
+ raise TypeError(msg)
164
+
165
+ if factory is not None:
166
+ if default is not NOTHING:
167
+ msg = (
168
+ "The `default` and `factory` arguments are mutually exclusive."
169
+ )
170
+ raise ValueError(msg)
171
+ if not callable(factory):
172
+ msg = "The `factory` argument must be a callable."
173
+ raise ValueError(msg)
174
+ default = Factory(factory)
175
+
176
+ if metadata is None:
177
+ metadata = {}
178
+
179
+ # Apply syntactic sugar by auto-wrapping.
180
+ if isinstance(on_setattr, (list, tuple)):
181
+ on_setattr = setters.pipe(*on_setattr)
182
+
183
+ if validator and isinstance(validator, (list, tuple)):
184
+ validator = and_(*validator)
185
+
186
+ if converter and isinstance(converter, (list, tuple)):
187
+ converter = pipe(*converter)
188
+
189
+ return _CountingAttr(
190
+ default=default,
191
+ validator=validator,
192
+ repr=repr,
193
+ cmp=None,
194
+ hash=hash,
195
+ init=init,
196
+ converter=converter,
197
+ metadata=metadata,
198
+ type=type,
199
+ kw_only=kw_only,
200
+ eq=eq,
201
+ eq_key=eq_key,
202
+ order=order,
203
+ order_key=order_key,
204
+ on_setattr=on_setattr,
205
+ alias=alias,
206
+ )
207
+
208
+
209
+ def _compile_and_eval(script, globs, locs=None, filename=""):
210
+ """
211
+ Evaluate the script with the given global (globs) and local (locs)
212
+ variables.
213
+ """
214
+ bytecode = compile(script, filename, "exec")
215
+ eval(bytecode, globs, locs)
216
+
217
+
218
+ def _make_method(name, script, filename, globs, locals=None):
219
+ """
220
+ Create the method with the script given and return the method object.
221
+ """
222
+ locs = {} if locals is None else locals
223
+
224
+ # In order of debuggers like PDB being able to step through the code,
225
+ # we add a fake linecache entry.
226
+ count = 1
227
+ base_filename = filename
228
+ while True:
229
+ linecache_tuple = (
230
+ len(script),
231
+ None,
232
+ script.splitlines(True),
233
+ filename,
234
+ )
235
+ old_val = linecache.cache.setdefault(filename, linecache_tuple)
236
+ if old_val == linecache_tuple:
237
+ break
238
+
239
+ filename = f"{base_filename[:-1]}-{count}>"
240
+ count += 1
241
+
242
+ _compile_and_eval(script, globs, locs, filename)
243
+
244
+ return locs[name]
245
+
246
+
247
+ def _make_attr_tuple_class(cls_name, attr_names):
248
+ """
249
+ Create a tuple subclass to hold `Attribute`s for an `attrs` class.
250
+
251
+ The subclass is a bare tuple with properties for names.
252
+
253
+ class MyClassAttributes(tuple):
254
+ __slots__ = ()
255
+ x = property(itemgetter(0))
256
+ """
257
+ attr_class_name = f"{cls_name}Attributes"
258
+ attr_class_template = [
259
+ f"class {attr_class_name}(tuple):",
260
+ " __slots__ = ()",
261
+ ]
262
+ if attr_names:
263
+ for i, attr_name in enumerate(attr_names):
264
+ attr_class_template.append(
265
+ f" {attr_name} = _attrs_property(_attrs_itemgetter({i}))"
266
+ )
267
+ else:
268
+ attr_class_template.append(" pass")
269
+ globs = {"_attrs_itemgetter": itemgetter, "_attrs_property": property}
270
+ _compile_and_eval("\n".join(attr_class_template), globs)
271
+ return globs[attr_class_name]
272
+
273
+
274
+ # Tuple class for extracted attributes from a class definition.
275
+ # `base_attrs` is a subset of `attrs`.
276
+ _Attributes = _make_attr_tuple_class(
277
+ "_Attributes",
278
+ [
279
+ # all attributes to build dunder methods for
280
+ "attrs",
281
+ # attributes that have been inherited
282
+ "base_attrs",
283
+ # map inherited attributes to their originating classes
284
+ "base_attrs_map",
285
+ ],
286
+ )
287
+
288
+
289
+ def _is_class_var(annot):
290
+ """
291
+ Check whether *annot* is a typing.ClassVar.
292
+
293
+ The string comparison hack is used to avoid evaluating all string
294
+ annotations which would put attrs-based classes at a performance
295
+ disadvantage compared to plain old classes.
296
+ """
297
+ annot = str(annot)
298
+
299
+ # Annotation can be quoted.
300
+ if annot.startswith(("'", '"')) and annot.endswith(("'", '"')):
301
+ annot = annot[1:-1]
302
+
303
+ return annot.startswith(_CLASSVAR_PREFIXES)
304
+
305
+
306
+ def _has_own_attribute(cls, attrib_name):
307
+ """
308
+ Check whether *cls* defines *attrib_name* (and doesn't just inherit it).
309
+ """
310
+ return attrib_name in cls.__dict__
311
+
312
+
313
+ def _collect_base_attrs(cls, taken_attr_names):
314
+ """
315
+ Collect attr.ibs from base classes of *cls*, except *taken_attr_names*.
316
+ """
317
+ base_attrs = []
318
+ base_attr_map = {} # A dictionary of base attrs to their classes.
319
+
320
+ # Traverse the MRO and collect attributes.
321
+ for base_cls in reversed(cls.__mro__[1:-1]):
322
+ for a in getattr(base_cls, "__attrs_attrs__", []):
323
+ if a.inherited or a.name in taken_attr_names:
324
+ continue
325
+
326
+ a = a.evolve(inherited=True) # noqa: PLW2901
327
+ base_attrs.append(a)
328
+ base_attr_map[a.name] = base_cls
329
+
330
+ # For each name, only keep the freshest definition i.e. the furthest at the
331
+ # back. base_attr_map is fine because it gets overwritten with every new
332
+ # instance.
333
+ filtered = []
334
+ seen = set()
335
+ for a in reversed(base_attrs):
336
+ if a.name in seen:
337
+ continue
338
+ filtered.insert(0, a)
339
+ seen.add(a.name)
340
+
341
+ return filtered, base_attr_map
342
+
343
+
344
+ def _collect_base_attrs_broken(cls, taken_attr_names):
345
+ """
346
+ Collect attr.ibs from base classes of *cls*, except *taken_attr_names*.
347
+
348
+ N.B. *taken_attr_names* will be mutated.
349
+
350
+ Adhere to the old incorrect behavior.
351
+
352
+ Notably it collects from the front and considers inherited attributes which
353
+ leads to the buggy behavior reported in #428.
354
+ """
355
+ base_attrs = []
356
+ base_attr_map = {} # A dictionary of base attrs to their classes.
357
+
358
+ # Traverse the MRO and collect attributes.
359
+ for base_cls in cls.__mro__[1:-1]:
360
+ for a in getattr(base_cls, "__attrs_attrs__", []):
361
+ if a.name in taken_attr_names:
362
+ continue
363
+
364
+ a = a.evolve(inherited=True) # noqa: PLW2901
365
+ taken_attr_names.add(a.name)
366
+ base_attrs.append(a)
367
+ base_attr_map[a.name] = base_cls
368
+
369
+ return base_attrs, base_attr_map
370
+
371
+
372
+ def _transform_attrs(
373
+ cls, these, auto_attribs, kw_only, collect_by_mro, field_transformer
374
+ ):
375
+ """
376
+ Transform all `_CountingAttr`s on a class into `Attribute`s.
377
+
378
+ If *these* is passed, use that and don't look for them on the class.
379
+
380
+ If *collect_by_mro* is True, collect them in the correct MRO order,
381
+ otherwise use the old -- incorrect -- order. See #428.
382
+
383
+ Return an `_Attributes`.
384
+ """
385
+ cd = cls.__dict__
386
+ anns = _get_annotations(cls)
387
+
388
+ if these is not None:
389
+ ca_list = list(these.items())
390
+ elif auto_attribs is True:
391
+ ca_names = {
392
+ name
393
+ for name, attr in cd.items()
394
+ if isinstance(attr, _CountingAttr)
395
+ }
396
+ ca_list = []
397
+ annot_names = set()
398
+ for attr_name, type in anns.items():
399
+ if _is_class_var(type):
400
+ continue
401
+ annot_names.add(attr_name)
402
+ a = cd.get(attr_name, NOTHING)
403
+
404
+ if not isinstance(a, _CountingAttr):
405
+ a = attrib() if a is NOTHING else attrib(default=a)
406
+ ca_list.append((attr_name, a))
407
+
408
+ unannotated = ca_names - annot_names
409
+ if len(unannotated) > 0:
410
+ raise UnannotatedAttributeError(
411
+ "The following `attr.ib`s lack a type annotation: "
412
+ + ", ".join(
413
+ sorted(unannotated, key=lambda n: cd.get(n).counter)
414
+ )
415
+ + "."
416
+ )
417
+ else:
418
+ ca_list = sorted(
419
+ (
420
+ (name, attr)
421
+ for name, attr in cd.items()
422
+ if isinstance(attr, _CountingAttr)
423
+ ),
424
+ key=lambda e: e[1].counter,
425
+ )
426
+
427
+ own_attrs = [
428
+ Attribute.from_counting_attr(
429
+ name=attr_name, ca=ca, type=anns.get(attr_name)
430
+ )
431
+ for attr_name, ca in ca_list
432
+ ]
433
+
434
+ if collect_by_mro:
435
+ base_attrs, base_attr_map = _collect_base_attrs(
436
+ cls, {a.name for a in own_attrs}
437
+ )
438
+ else:
439
+ base_attrs, base_attr_map = _collect_base_attrs_broken(
440
+ cls, {a.name for a in own_attrs}
441
+ )
442
+
443
+ if kw_only:
444
+ own_attrs = [a.evolve(kw_only=True) for a in own_attrs]
445
+ base_attrs = [a.evolve(kw_only=True) for a in base_attrs]
446
+
447
+ attrs = base_attrs + own_attrs
448
+
449
+ # Mandatory vs non-mandatory attr order only matters when they are part of
450
+ # the __init__ signature and when they aren't kw_only (which are moved to
451
+ # the end and can be mandatory or non-mandatory in any order, as they will
452
+ # be specified as keyword args anyway). Check the order of those attrs:
453
+ had_default = False
454
+ for a in (a for a in attrs if a.init is not False and a.kw_only is False):
455
+ if had_default is True and a.default is NOTHING:
456
+ msg = f"No mandatory attributes allowed after an attribute with a default value or factory. Attribute in question: {a!r}"
457
+ raise ValueError(msg)
458
+
459
+ if had_default is False and a.default is not NOTHING:
460
+ had_default = True
461
+
462
+ if field_transformer is not None:
463
+ attrs = field_transformer(cls, attrs)
464
+
465
+ # Resolve default field alias after executing field_transformer.
466
+ # This allows field_transformer to differentiate between explicit vs
467
+ # default aliases and supply their own defaults.
468
+ attrs = [
469
+ a.evolve(alias=_default_init_alias_for(a.name)) if not a.alias else a
470
+ for a in attrs
471
+ ]
472
+
473
+ # Create AttrsClass *after* applying the field_transformer since it may
474
+ # add or remove attributes!
475
+ attr_names = [a.name for a in attrs]
476
+ AttrsClass = _make_attr_tuple_class(cls.__name__, attr_names)
477
+
478
+ return _Attributes((AttrsClass(attrs), base_attrs, base_attr_map))
479
+
480
+
481
+ def _make_cached_property_getattr(cached_properties, original_getattr, cls):
482
+ lines = [
483
+ # Wrapped to get `__class__` into closure cell for super()
484
+ # (It will be replaced with the newly constructed class after construction).
485
+ "def wrapper(_cls):",
486
+ " __class__ = _cls",
487
+ " def __getattr__(self, item, cached_properties=cached_properties, original_getattr=original_getattr, _cached_setattr_get=_cached_setattr_get):",
488
+ " func = cached_properties.get(item)",
489
+ " if func is not None:",
490
+ " result = func(self)",
491
+ " _setter = _cached_setattr_get(self)",
492
+ " _setter(item, result)",
493
+ " return result",
494
+ ]
495
+ if original_getattr is not None:
496
+ lines.append(
497
+ " return original_getattr(self, item)",
498
+ )
499
+ else:
500
+ lines.extend(
501
+ [
502
+ " try:",
503
+ " return super().__getattribute__(item)",
504
+ " except AttributeError:",
505
+ " if not hasattr(super(), '__getattr__'):",
506
+ " raise",
507
+ " return super().__getattr__(item)",
508
+ " original_error = f\"'{self.__class__.__name__}' object has no attribute '{item}'\"",
509
+ " raise AttributeError(original_error)",
510
+ ]
511
+ )
512
+
513
+ lines.extend(
514
+ [
515
+ " return __getattr__",
516
+ "__getattr__ = wrapper(_cls)",
517
+ ]
518
+ )
519
+
520
+ unique_filename = _generate_unique_filename(cls, "getattr")
521
+
522
+ glob = {
523
+ "cached_properties": cached_properties,
524
+ "_cached_setattr_get": _OBJ_SETATTR.__get__,
525
+ "original_getattr": original_getattr,
526
+ }
527
+
528
+ return _make_method(
529
+ "__getattr__",
530
+ "\n".join(lines),
531
+ unique_filename,
532
+ glob,
533
+ locals={
534
+ "_cls": cls,
535
+ },
536
+ )
537
+
538
+
539
+ def _frozen_setattrs(self, name, value):
540
+ """
541
+ Attached to frozen classes as __setattr__.
542
+ """
543
+ if isinstance(self, BaseException) and name in (
544
+ "__cause__",
545
+ "__context__",
546
+ "__traceback__",
547
+ ):
548
+ BaseException.__setattr__(self, name, value)
549
+ return
550
+
551
+ raise FrozenInstanceError()
552
+
553
+
554
+ def _frozen_delattrs(self, name):
555
+ """
556
+ Attached to frozen classes as __delattr__.
557
+ """
558
+ raise FrozenInstanceError()
559
+
560
+
561
+ class _ClassBuilder:
562
+ """
563
+ Iteratively build *one* class.
564
+ """
565
+
566
+ __slots__ = (
567
+ "_attr_names",
568
+ "_attrs",
569
+ "_base_attr_map",
570
+ "_base_names",
571
+ "_cache_hash",
572
+ "_cls",
573
+ "_cls_dict",
574
+ "_delete_attribs",
575
+ "_frozen",
576
+ "_has_pre_init",
577
+ "_pre_init_has_args",
578
+ "_has_post_init",
579
+ "_is_exc",
580
+ "_on_setattr",
581
+ "_slots",
582
+ "_weakref_slot",
583
+ "_wrote_own_setattr",
584
+ "_has_custom_setattr",
585
+ )
586
+
587
+ def __init__(
588
+ self,
589
+ cls,
590
+ these,
591
+ slots,
592
+ frozen,
593
+ weakref_slot,
594
+ getstate_setstate,
595
+ auto_attribs,
596
+ kw_only,
597
+ cache_hash,
598
+ is_exc,
599
+ collect_by_mro,
600
+ on_setattr,
601
+ has_custom_setattr,
602
+ field_transformer,
603
+ ):
604
+ attrs, base_attrs, base_map = _transform_attrs(
605
+ cls,
606
+ these,
607
+ auto_attribs,
608
+ kw_only,
609
+ collect_by_mro,
610
+ field_transformer,
611
+ )
612
+
613
+ self._cls = cls
614
+ self._cls_dict = dict(cls.__dict__) if slots else {}
615
+ self._attrs = attrs
616
+ self._base_names = {a.name for a in base_attrs}
617
+ self._base_attr_map = base_map
618
+ self._attr_names = tuple(a.name for a in attrs)
619
+ self._slots = slots
620
+ self._frozen = frozen
621
+ self._weakref_slot = weakref_slot
622
+ self._cache_hash = cache_hash
623
+ self._has_pre_init = bool(getattr(cls, "__attrs_pre_init__", False))
624
+ self._pre_init_has_args = False
625
+ if self._has_pre_init:
626
+ # Check if the pre init method has more arguments than just `self`
627
+ # We want to pass arguments if pre init expects arguments
628
+ pre_init_func = cls.__attrs_pre_init__
629
+ pre_init_signature = inspect.signature(pre_init_func)
630
+ self._pre_init_has_args = len(pre_init_signature.parameters) > 1
631
+ self._has_post_init = bool(getattr(cls, "__attrs_post_init__", False))
632
+ self._delete_attribs = not bool(these)
633
+ self._is_exc = is_exc
634
+ self._on_setattr = on_setattr
635
+
636
+ self._has_custom_setattr = has_custom_setattr
637
+ self._wrote_own_setattr = False
638
+
639
+ self._cls_dict["__attrs_attrs__"] = self._attrs
640
+
641
+ if frozen:
642
+ self._cls_dict["__setattr__"] = _frozen_setattrs
643
+ self._cls_dict["__delattr__"] = _frozen_delattrs
644
+
645
+ self._wrote_own_setattr = True
646
+ elif on_setattr in (
647
+ _DEFAULT_ON_SETATTR,
648
+ setters.validate,
649
+ setters.convert,
650
+ ):
651
+ has_validator = has_converter = False
652
+ for a in attrs:
653
+ if a.validator is not None:
654
+ has_validator = True
655
+ if a.converter is not None:
656
+ has_converter = True
657
+
658
+ if has_validator and has_converter:
659
+ break
660
+ if (
661
+ (
662
+ on_setattr == _DEFAULT_ON_SETATTR
663
+ and not (has_validator or has_converter)
664
+ )
665
+ or (on_setattr == setters.validate and not has_validator)
666
+ or (on_setattr == setters.convert and not has_converter)
667
+ ):
668
+ # If class-level on_setattr is set to convert + validate, but
669
+ # there's no field to convert or validate, pretend like there's
670
+ # no on_setattr.
671
+ self._on_setattr = None
672
+
673
+ if getstate_setstate:
674
+ (
675
+ self._cls_dict["__getstate__"],
676
+ self._cls_dict["__setstate__"],
677
+ ) = self._make_getstate_setstate()
678
+
679
+ def __repr__(self):
680
+ return f"<_ClassBuilder(cls={self._cls.__name__})>"
681
+
682
+ def build_class(self):
683
+ """
684
+ Finalize class based on the accumulated configuration.
685
+
686
+ Builder cannot be used after calling this method.
687
+ """
688
+ if self._slots is True:
689
+ cls = self._create_slots_class()
690
+ else:
691
+ cls = self._patch_original_class()
692
+ if PY_3_10_PLUS:
693
+ cls = abc.update_abstractmethods(cls)
694
+
695
+ # The method gets only called if it's not inherited from a base class.
696
+ # _has_own_attribute does NOT work properly for classmethods.
697
+ if (
698
+ getattr(cls, "__attrs_init_subclass__", None)
699
+ and "__attrs_init_subclass__" not in cls.__dict__
700
+ ):
701
+ cls.__attrs_init_subclass__()
702
+
703
+ return cls
704
+
705
+ def _patch_original_class(self):
706
+ """
707
+ Apply accumulated methods and return the class.
708
+ """
709
+ cls = self._cls
710
+ base_names = self._base_names
711
+
712
+ # Clean class of attribute definitions (`attr.ib()`s).
713
+ if self._delete_attribs:
714
+ for name in self._attr_names:
715
+ if (
716
+ name not in base_names
717
+ and getattr(cls, name, _SENTINEL) is not _SENTINEL
718
+ ):
719
+ # An AttributeError can happen if a base class defines a
720
+ # class variable and we want to set an attribute with the
721
+ # same name by using only a type annotation.
722
+ with contextlib.suppress(AttributeError):
723
+ delattr(cls, name)
724
+
725
+ # Attach our dunder methods.
726
+ for name, value in self._cls_dict.items():
727
+ setattr(cls, name, value)
728
+
729
+ # If we've inherited an attrs __setattr__ and don't write our own,
730
+ # reset it to object's.
731
+ if not self._wrote_own_setattr and getattr(
732
+ cls, "__attrs_own_setattr__", False
733
+ ):
734
+ cls.__attrs_own_setattr__ = False
735
+
736
+ if not self._has_custom_setattr:
737
+ cls.__setattr__ = _OBJ_SETATTR
738
+
739
+ return cls
740
+
741
+ def _create_slots_class(self):
742
+ """
743
+ Build and return a new class with a `__slots__` attribute.
744
+ """
745
+ cd = {
746
+ k: v
747
+ for k, v in self._cls_dict.items()
748
+ if k not in (*tuple(self._attr_names), "__dict__", "__weakref__")
749
+ }
750
+
751
+ # If our class doesn't have its own implementation of __setattr__
752
+ # (either from the user or by us), check the bases, if one of them has
753
+ # an attrs-made __setattr__, that needs to be reset. We don't walk the
754
+ # MRO because we only care about our immediate base classes.
755
+ # XXX: This can be confused by subclassing a slotted attrs class with
756
+ # XXX: a non-attrs class and subclass the resulting class with an attrs
757
+ # XXX: class. See `test_slotted_confused` for details. For now that's
758
+ # XXX: OK with us.
759
+ if not self._wrote_own_setattr:
760
+ cd["__attrs_own_setattr__"] = False
761
+
762
+ if not self._has_custom_setattr:
763
+ for base_cls in self._cls.__bases__:
764
+ if base_cls.__dict__.get("__attrs_own_setattr__", False):
765
+ cd["__setattr__"] = _OBJ_SETATTR
766
+ break
767
+
768
+ # Traverse the MRO to collect existing slots
769
+ # and check for an existing __weakref__.
770
+ existing_slots = {}
771
+ weakref_inherited = False
772
+ for base_cls in self._cls.__mro__[1:-1]:
773
+ if base_cls.__dict__.get("__weakref__", None) is not None:
774
+ weakref_inherited = True
775
+ existing_slots.update(
776
+ {
777
+ name: getattr(base_cls, name)
778
+ for name in getattr(base_cls, "__slots__", [])
779
+ }
780
+ )
781
+
782
+ base_names = set(self._base_names)
783
+
784
+ names = self._attr_names
785
+ if (
786
+ self._weakref_slot
787
+ and "__weakref__" not in getattr(self._cls, "__slots__", ())
788
+ and "__weakref__" not in names
789
+ and not weakref_inherited
790
+ ):
791
+ names += ("__weakref__",)
792
+
793
+ if PY_3_8_PLUS:
794
+ cached_properties = {
795
+ name: cached_property.func
796
+ for name, cached_property in cd.items()
797
+ if isinstance(cached_property, functools.cached_property)
798
+ }
799
+ else:
800
+ # `functools.cached_property` was introduced in 3.8.
801
+ # So can't be used before this.
802
+ cached_properties = {}
803
+
804
+ # Collect methods with a `__class__` reference that are shadowed in the new class.
805
+ # To know to update them.
806
+ additional_closure_functions_to_update = []
807
+ if cached_properties:
808
+ class_annotations = _get_annotations(self._cls)
809
+ for name, func in cached_properties.items():
810
+ # Add cached properties to names for slotting.
811
+ names += (name,)
812
+ # Clear out function from class to avoid clashing.
813
+ del cd[name]
814
+ additional_closure_functions_to_update.append(func)
815
+ annotation = inspect.signature(func).return_annotation
816
+ if annotation is not inspect.Parameter.empty:
817
+ class_annotations[name] = annotation
818
+
819
+ original_getattr = cd.get("__getattr__")
820
+ if original_getattr is not None:
821
+ additional_closure_functions_to_update.append(original_getattr)
822
+
823
+ cd["__getattr__"] = _make_cached_property_getattr(
824
+ cached_properties, original_getattr, self._cls
825
+ )
826
+
827
+ # We only add the names of attributes that aren't inherited.
828
+ # Setting __slots__ to inherited attributes wastes memory.
829
+ slot_names = [name for name in names if name not in base_names]
830
+
831
+ # There are slots for attributes from current class
832
+ # that are defined in parent classes.
833
+ # As their descriptors may be overridden by a child class,
834
+ # we collect them here and update the class dict
835
+ reused_slots = {
836
+ slot: slot_descriptor
837
+ for slot, slot_descriptor in existing_slots.items()
838
+ if slot in slot_names
839
+ }
840
+ slot_names = [name for name in slot_names if name not in reused_slots]
841
+ cd.update(reused_slots)
842
+ if self._cache_hash:
843
+ slot_names.append(_HASH_CACHE_FIELD)
844
+
845
+ cd["__slots__"] = tuple(slot_names)
846
+
847
+ cd["__qualname__"] = self._cls.__qualname__
848
+
849
+ # Create new class based on old class and our methods.
850
+ cls = type(self._cls)(self._cls.__name__, self._cls.__bases__, cd)
851
+
852
+ # The following is a fix for
853
+ # <https://github.com/python-attrs/attrs/issues/102>.
854
+ # If a method mentions `__class__` or uses the no-arg super(), the
855
+ # compiler will bake a reference to the class in the method itself
856
+ # as `method.__closure__`. Since we replace the class with a
857
+ # clone, we rewrite these references so it keeps working.
858
+ for item in itertools.chain(
859
+ cls.__dict__.values(), additional_closure_functions_to_update
860
+ ):
861
+ if isinstance(item, (classmethod, staticmethod)):
862
+ # Class- and staticmethods hide their functions inside.
863
+ # These might need to be rewritten as well.
864
+ closure_cells = getattr(item.__func__, "__closure__", None)
865
+ elif isinstance(item, property):
866
+ # Workaround for property `super()` shortcut (PY3-only).
867
+ # There is no universal way for other descriptors.
868
+ closure_cells = getattr(item.fget, "__closure__", None)
869
+ else:
870
+ closure_cells = getattr(item, "__closure__", None)
871
+
872
+ if not closure_cells: # Catch None or the empty list.
873
+ continue
874
+ for cell in closure_cells:
875
+ try:
876
+ match = cell.cell_contents is self._cls
877
+ except ValueError: # noqa: PERF203
878
+ # ValueError: Cell is empty
879
+ pass
880
+ else:
881
+ if match:
882
+ cell.cell_contents = cls
883
+ return cls
884
+
885
+ def add_repr(self, ns):
886
+ self._cls_dict["__repr__"] = self._add_method_dunders(
887
+ _make_repr(self._attrs, ns, self._cls)
888
+ )
889
+ return self
890
+
891
+ def add_str(self):
892
+ repr = self._cls_dict.get("__repr__")
893
+ if repr is None:
894
+ msg = "__str__ can only be generated if a __repr__ exists."
895
+ raise ValueError(msg)
896
+
897
+ def __str__(self):
898
+ return self.__repr__()
899
+
900
+ self._cls_dict["__str__"] = self._add_method_dunders(__str__)
901
+ return self
902
+
903
+ def _make_getstate_setstate(self):
904
+ """
905
+ Create custom __setstate__ and __getstate__ methods.
906
+ """
907
+ # __weakref__ is not writable.
908
+ state_attr_names = tuple(
909
+ an for an in self._attr_names if an != "__weakref__"
910
+ )
911
+
912
+ def slots_getstate(self):
913
+ """
914
+ Automatically created by attrs.
915
+ """
916
+ return {name: getattr(self, name) for name in state_attr_names}
917
+
918
+ hash_caching_enabled = self._cache_hash
919
+
920
+ def slots_setstate(self, state):
921
+ """
922
+ Automatically created by attrs.
923
+ """
924
+ __bound_setattr = _OBJ_SETATTR.__get__(self)
925
+ if isinstance(state, tuple):
926
+ # Backward compatibility with attrs instances pickled with
927
+ # attrs versions before v22.2.0 which stored tuples.
928
+ for name, value in zip(state_attr_names, state):
929
+ __bound_setattr(name, value)
930
+ else:
931
+ for name in state_attr_names:
932
+ if name in state:
933
+ __bound_setattr(name, state[name])
934
+
935
+ # The hash code cache is not included when the object is
936
+ # serialized, but it still needs to be initialized to None to
937
+ # indicate that the first call to __hash__ should be a cache
938
+ # miss.
939
+ if hash_caching_enabled:
940
+ __bound_setattr(_HASH_CACHE_FIELD, None)
941
+
942
+ return slots_getstate, slots_setstate
943
+
944
+ def make_unhashable(self):
945
+ self._cls_dict["__hash__"] = None
946
+ return self
947
+
948
+ def add_hash(self):
949
+ self._cls_dict["__hash__"] = self._add_method_dunders(
950
+ _make_hash(
951
+ self._cls,
952
+ self._attrs,
953
+ frozen=self._frozen,
954
+ cache_hash=self._cache_hash,
955
+ )
956
+ )
957
+
958
+ return self
959
+
960
+ def add_init(self):
961
+ self._cls_dict["__init__"] = self._add_method_dunders(
962
+ _make_init(
963
+ self._cls,
964
+ self._attrs,
965
+ self._has_pre_init,
966
+ self._pre_init_has_args,
967
+ self._has_post_init,
968
+ self._frozen,
969
+ self._slots,
970
+ self._cache_hash,
971
+ self._base_attr_map,
972
+ self._is_exc,
973
+ self._on_setattr,
974
+ attrs_init=False,
975
+ )
976
+ )
977
+
978
+ return self
979
+
980
+ def add_match_args(self):
981
+ self._cls_dict["__match_args__"] = tuple(
982
+ field.name
983
+ for field in self._attrs
984
+ if field.init and not field.kw_only
985
+ )
986
+
987
+ def add_attrs_init(self):
988
+ self._cls_dict["__attrs_init__"] = self._add_method_dunders(
989
+ _make_init(
990
+ self._cls,
991
+ self._attrs,
992
+ self._has_pre_init,
993
+ self._pre_init_has_args,
994
+ self._has_post_init,
995
+ self._frozen,
996
+ self._slots,
997
+ self._cache_hash,
998
+ self._base_attr_map,
999
+ self._is_exc,
1000
+ self._on_setattr,
1001
+ attrs_init=True,
1002
+ )
1003
+ )
1004
+
1005
+ return self
1006
+
1007
+ def add_eq(self):
1008
+ cd = self._cls_dict
1009
+
1010
+ cd["__eq__"] = self._add_method_dunders(
1011
+ _make_eq(self._cls, self._attrs)
1012
+ )
1013
+ cd["__ne__"] = self._add_method_dunders(_make_ne())
1014
+
1015
+ return self
1016
+
1017
+ def add_order(self):
1018
+ cd = self._cls_dict
1019
+
1020
+ cd["__lt__"], cd["__le__"], cd["__gt__"], cd["__ge__"] = (
1021
+ self._add_method_dunders(meth)
1022
+ for meth in _make_order(self._cls, self._attrs)
1023
+ )
1024
+
1025
+ return self
1026
+
1027
+ def add_setattr(self):
1028
+ if self._frozen:
1029
+ return self
1030
+
1031
+ sa_attrs = {}
1032
+ for a in self._attrs:
1033
+ on_setattr = a.on_setattr or self._on_setattr
1034
+ if on_setattr and on_setattr is not setters.NO_OP:
1035
+ sa_attrs[a.name] = a, on_setattr
1036
+
1037
+ if not sa_attrs:
1038
+ return self
1039
+
1040
+ if self._has_custom_setattr:
1041
+ # We need to write a __setattr__ but there already is one!
1042
+ msg = "Can't combine custom __setattr__ with on_setattr hooks."
1043
+ raise ValueError(msg)
1044
+
1045
+ # docstring comes from _add_method_dunders
1046
+ def __setattr__(self, name, val):
1047
+ try:
1048
+ a, hook = sa_attrs[name]
1049
+ except KeyError:
1050
+ nval = val
1051
+ else:
1052
+ nval = hook(self, a, val)
1053
+
1054
+ _OBJ_SETATTR(self, name, nval)
1055
+
1056
+ self._cls_dict["__attrs_own_setattr__"] = True
1057
+ self._cls_dict["__setattr__"] = self._add_method_dunders(__setattr__)
1058
+ self._wrote_own_setattr = True
1059
+
1060
+ return self
1061
+
1062
+ def _add_method_dunders(self, method):
1063
+ """
1064
+ Add __module__ and __qualname__ to a *method* if possible.
1065
+ """
1066
+ with contextlib.suppress(AttributeError):
1067
+ method.__module__ = self._cls.__module__
1068
+
1069
+ with contextlib.suppress(AttributeError):
1070
+ method.__qualname__ = f"{self._cls.__qualname__}.{method.__name__}"
1071
+
1072
+ with contextlib.suppress(AttributeError):
1073
+ method.__doc__ = (
1074
+ "Method generated by attrs for class "
1075
+ f"{self._cls.__qualname__}."
1076
+ )
1077
+
1078
+ return method
1079
+
1080
+
1081
+ def _determine_attrs_eq_order(cmp, eq, order, default_eq):
1082
+ """
1083
+ Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
1084
+ values of eq and order. If *eq* is None, set it to *default_eq*.
1085
+ """
1086
+ if cmp is not None and any((eq is not None, order is not None)):
1087
+ msg = "Don't mix `cmp` with `eq' and `order`."
1088
+ raise ValueError(msg)
1089
+
1090
+ # cmp takes precedence due to bw-compatibility.
1091
+ if cmp is not None:
1092
+ return cmp, cmp
1093
+
1094
+ # If left None, equality is set to the specified default and ordering
1095
+ # mirrors equality.
1096
+ if eq is None:
1097
+ eq = default_eq
1098
+
1099
+ if order is None:
1100
+ order = eq
1101
+
1102
+ if eq is False and order is True:
1103
+ msg = "`order` can only be True if `eq` is True too."
1104
+ raise ValueError(msg)
1105
+
1106
+ return eq, order
1107
+
1108
+
1109
+ def _determine_attrib_eq_order(cmp, eq, order, default_eq):
1110
+ """
1111
+ Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
1112
+ values of eq and order. If *eq* is None, set it to *default_eq*.
1113
+ """
1114
+ if cmp is not None and any((eq is not None, order is not None)):
1115
+ msg = "Don't mix `cmp` with `eq' and `order`."
1116
+ raise ValueError(msg)
1117
+
1118
+ def decide_callable_or_boolean(value):
1119
+ """
1120
+ Decide whether a key function is used.
1121
+ """
1122
+ if callable(value):
1123
+ value, key = True, value
1124
+ else:
1125
+ key = None
1126
+ return value, key
1127
+
1128
+ # cmp takes precedence due to bw-compatibility.
1129
+ if cmp is not None:
1130
+ cmp, cmp_key = decide_callable_or_boolean(cmp)
1131
+ return cmp, cmp_key, cmp, cmp_key
1132
+
1133
+ # If left None, equality is set to the specified default and ordering
1134
+ # mirrors equality.
1135
+ if eq is None:
1136
+ eq, eq_key = default_eq, None
1137
+ else:
1138
+ eq, eq_key = decide_callable_or_boolean(eq)
1139
+
1140
+ if order is None:
1141
+ order, order_key = eq, eq_key
1142
+ else:
1143
+ order, order_key = decide_callable_or_boolean(order)
1144
+
1145
+ if eq is False and order is True:
1146
+ msg = "`order` can only be True if `eq` is True too."
1147
+ raise ValueError(msg)
1148
+
1149
+ return eq, eq_key, order, order_key
1150
+
1151
+
1152
+ def _determine_whether_to_implement(
1153
+ cls, flag, auto_detect, dunders, default=True
1154
+ ):
1155
+ """
1156
+ Check whether we should implement a set of methods for *cls*.
1157
+
1158
+ *flag* is the argument passed into @attr.s like 'init', *auto_detect* the
1159
+ same as passed into @attr.s and *dunders* is a tuple of attribute names
1160
+ whose presence signal that the user has implemented it themselves.
1161
+
1162
+ Return *default* if no reason for either for or against is found.
1163
+ """
1164
+ if flag is True or flag is False:
1165
+ return flag
1166
+
1167
+ if flag is None and auto_detect is False:
1168
+ return default
1169
+
1170
+ # Logically, flag is None and auto_detect is True here.
1171
+ for dunder in dunders:
1172
+ if _has_own_attribute(cls, dunder):
1173
+ return False
1174
+
1175
+ return default
1176
+
1177
+
1178
+ def attrs(
1179
+ maybe_cls=None,
1180
+ these=None,
1181
+ repr_ns=None,
1182
+ repr=None,
1183
+ cmp=None,
1184
+ hash=None,
1185
+ init=None,
1186
+ slots=False,
1187
+ frozen=False,
1188
+ weakref_slot=True,
1189
+ str=False,
1190
+ auto_attribs=False,
1191
+ kw_only=False,
1192
+ cache_hash=False,
1193
+ auto_exc=False,
1194
+ eq=None,
1195
+ order=None,
1196
+ auto_detect=False,
1197
+ collect_by_mro=False,
1198
+ getstate_setstate=None,
1199
+ on_setattr=None,
1200
+ field_transformer=None,
1201
+ match_args=True,
1202
+ unsafe_hash=None,
1203
+ ):
1204
+ r"""
1205
+ A class decorator that adds :term:`dunder methods` according to the
1206
+ specified attributes using `attr.ib` or the *these* argument.
1207
+
1208
+ Consider using `attrs.define` / `attrs.frozen` in new code (``attr.s`` will
1209
+ *never* go away, though).
1210
+
1211
+ Args:
1212
+ repr_ns (str):
1213
+ When using nested classes, there was no way in Python 2 to
1214
+ automatically detect that. This argument allows to set a custom
1215
+ name for a more meaningful ``repr`` output. This argument is
1216
+ pointless in Python 3 and is therefore deprecated.
1217
+
1218
+ .. caution::
1219
+ Refer to `attrs.define` for the rest of the parameters, but note that they
1220
+ can have different defaults.
1221
+
1222
+ Notably, leaving *on_setattr* as `None` will **not** add any hooks.
1223
+
1224
+ .. versionadded:: 16.0.0 *slots*
1225
+ .. versionadded:: 16.1.0 *frozen*
1226
+ .. versionadded:: 16.3.0 *str*
1227
+ .. versionadded:: 16.3.0 Support for ``__attrs_post_init__``.
1228
+ .. versionchanged:: 17.1.0
1229
+ *hash* supports `None` as value which is also the default now.
1230
+ .. versionadded:: 17.3.0 *auto_attribs*
1231
+ .. versionchanged:: 18.1.0
1232
+ If *these* is passed, no attributes are deleted from the class body.
1233
+ .. versionchanged:: 18.1.0 If *these* is ordered, the order is retained.
1234
+ .. versionadded:: 18.2.0 *weakref_slot*
1235
+ .. deprecated:: 18.2.0
1236
+ ``__lt__``, ``__le__``, ``__gt__``, and ``__ge__`` now raise a
1237
+ `DeprecationWarning` if the classes compared are subclasses of
1238
+ each other. ``__eq`` and ``__ne__`` never tried to compared subclasses
1239
+ to each other.
1240
+ .. versionchanged:: 19.2.0
1241
+ ``__lt__``, ``__le__``, ``__gt__``, and ``__ge__`` now do not consider
1242
+ subclasses comparable anymore.
1243
+ .. versionadded:: 18.2.0 *kw_only*
1244
+ .. versionadded:: 18.2.0 *cache_hash*
1245
+ .. versionadded:: 19.1.0 *auto_exc*
1246
+ .. deprecated:: 19.2.0 *cmp* Removal on or after 2021-06-01.
1247
+ .. versionadded:: 19.2.0 *eq* and *order*
1248
+ .. versionadded:: 20.1.0 *auto_detect*
1249
+ .. versionadded:: 20.1.0 *collect_by_mro*
1250
+ .. versionadded:: 20.1.0 *getstate_setstate*
1251
+ .. versionadded:: 20.1.0 *on_setattr*
1252
+ .. versionadded:: 20.3.0 *field_transformer*
1253
+ .. versionchanged:: 21.1.0
1254
+ ``init=False`` injects ``__attrs_init__``
1255
+ .. versionchanged:: 21.1.0 Support for ``__attrs_pre_init__``
1256
+ .. versionchanged:: 21.1.0 *cmp* undeprecated
1257
+ .. versionadded:: 21.3.0 *match_args*
1258
+ .. versionadded:: 22.2.0
1259
+ *unsafe_hash* as an alias for *hash* (for :pep:`681` compliance).
1260
+ .. deprecated:: 24.1.0 *repr_ns*
1261
+ .. versionchanged:: 24.1.0
1262
+ Instances are not compared as tuples of attributes anymore, but using a
1263
+ big ``and`` condition. This is faster and has more correct behavior for
1264
+ uncomparable values like `math.nan`.
1265
+ .. versionadded:: 24.1.0
1266
+ If a class has an *inherited* classmethod called
1267
+ ``__attrs_init_subclass__``, it is executed after the class is created.
1268
+ .. deprecated:: 24.1.0 *hash* is deprecated in favor of *unsafe_hash*.
1269
+ """
1270
+ if repr_ns is not None:
1271
+ import warnings
1272
+
1273
+ warnings.warn(
1274
+ DeprecationWarning(
1275
+ "The `repr_ns` argument is deprecated and will be removed in or after August 2025."
1276
+ ),
1277
+ stacklevel=2,
1278
+ )
1279
+
1280
+ eq_, order_ = _determine_attrs_eq_order(cmp, eq, order, None)
1281
+
1282
+ # unsafe_hash takes precedence due to PEP 681.
1283
+ if unsafe_hash is not None:
1284
+ hash = unsafe_hash
1285
+
1286
+ if isinstance(on_setattr, (list, tuple)):
1287
+ on_setattr = setters.pipe(*on_setattr)
1288
+
1289
+ def wrap(cls):
1290
+ is_frozen = frozen or _has_frozen_base_class(cls)
1291
+ is_exc = auto_exc is True and issubclass(cls, BaseException)
1292
+ has_own_setattr = auto_detect and _has_own_attribute(
1293
+ cls, "__setattr__"
1294
+ )
1295
+
1296
+ if has_own_setattr and is_frozen:
1297
+ msg = "Can't freeze a class with a custom __setattr__."
1298
+ raise ValueError(msg)
1299
+
1300
+ builder = _ClassBuilder(
1301
+ cls,
1302
+ these,
1303
+ slots,
1304
+ is_frozen,
1305
+ weakref_slot,
1306
+ _determine_whether_to_implement(
1307
+ cls,
1308
+ getstate_setstate,
1309
+ auto_detect,
1310
+ ("__getstate__", "__setstate__"),
1311
+ default=slots,
1312
+ ),
1313
+ auto_attribs,
1314
+ kw_only,
1315
+ cache_hash,
1316
+ is_exc,
1317
+ collect_by_mro,
1318
+ on_setattr,
1319
+ has_own_setattr,
1320
+ field_transformer,
1321
+ )
1322
+ if _determine_whether_to_implement(
1323
+ cls, repr, auto_detect, ("__repr__",)
1324
+ ):
1325
+ builder.add_repr(repr_ns)
1326
+ if str is True:
1327
+ builder.add_str()
1328
+
1329
+ eq = _determine_whether_to_implement(
1330
+ cls, eq_, auto_detect, ("__eq__", "__ne__")
1331
+ )
1332
+ if not is_exc and eq is True:
1333
+ builder.add_eq()
1334
+ if not is_exc and _determine_whether_to_implement(
1335
+ cls, order_, auto_detect, ("__lt__", "__le__", "__gt__", "__ge__")
1336
+ ):
1337
+ builder.add_order()
1338
+
1339
+ builder.add_setattr()
1340
+
1341
+ nonlocal hash
1342
+ if (
1343
+ hash is None
1344
+ and auto_detect is True
1345
+ and _has_own_attribute(cls, "__hash__")
1346
+ ):
1347
+ hash = False
1348
+
1349
+ if hash is not True and hash is not False and hash is not None:
1350
+ # Can't use `hash in` because 1 == True for example.
1351
+ msg = "Invalid value for hash. Must be True, False, or None."
1352
+ raise TypeError(msg)
1353
+
1354
+ if hash is False or (hash is None and eq is False) or is_exc:
1355
+ # Don't do anything. Should fall back to __object__'s __hash__
1356
+ # which is by id.
1357
+ if cache_hash:
1358
+ msg = "Invalid value for cache_hash. To use hash caching, hashing must be either explicitly or implicitly enabled."
1359
+ raise TypeError(msg)
1360
+ elif hash is True or (
1361
+ hash is None and eq is True and is_frozen is True
1362
+ ):
1363
+ # Build a __hash__ if told so, or if it's safe.
1364
+ builder.add_hash()
1365
+ else:
1366
+ # Raise TypeError on attempts to hash.
1367
+ if cache_hash:
1368
+ msg = "Invalid value for cache_hash. To use hash caching, hashing must be either explicitly or implicitly enabled."
1369
+ raise TypeError(msg)
1370
+ builder.make_unhashable()
1371
+
1372
+ if _determine_whether_to_implement(
1373
+ cls, init, auto_detect, ("__init__",)
1374
+ ):
1375
+ builder.add_init()
1376
+ else:
1377
+ builder.add_attrs_init()
1378
+ if cache_hash:
1379
+ msg = "Invalid value for cache_hash. To use hash caching, init must be True."
1380
+ raise TypeError(msg)
1381
+
1382
+ if (
1383
+ PY_3_10_PLUS
1384
+ and match_args
1385
+ and not _has_own_attribute(cls, "__match_args__")
1386
+ ):
1387
+ builder.add_match_args()
1388
+
1389
+ return builder.build_class()
1390
+
1391
+ # maybe_cls's type depends on the usage of the decorator. It's a class
1392
+ # if it's used as `@attrs` but `None` if used as `@attrs()`.
1393
+ if maybe_cls is None:
1394
+ return wrap
1395
+
1396
+ return wrap(maybe_cls)
1397
+
1398
+
1399
+ _attrs = attrs
1400
+ """
1401
+ Internal alias so we can use it in functions that take an argument called
1402
+ *attrs*.
1403
+ """
1404
+
1405
+
1406
+ def _has_frozen_base_class(cls):
1407
+ """
1408
+ Check whether *cls* has a frozen ancestor by looking at its
1409
+ __setattr__.
1410
+ """
1411
+ return cls.__setattr__ is _frozen_setattrs
1412
+
1413
+
1414
+ def _generate_unique_filename(cls, func_name):
1415
+ """
1416
+ Create a "filename" suitable for a function being generated.
1417
+ """
1418
+ return (
1419
+ f"<attrs generated {func_name} {cls.__module__}."
1420
+ f"{getattr(cls, '__qualname__', cls.__name__)}>"
1421
+ )
1422
+
1423
+
1424
+ def _make_hash(cls, attrs, frozen, cache_hash):
1425
+ attrs = tuple(
1426
+ a for a in attrs if a.hash is True or (a.hash is None and a.eq is True)
1427
+ )
1428
+
1429
+ tab = " "
1430
+
1431
+ unique_filename = _generate_unique_filename(cls, "hash")
1432
+ type_hash = hash(unique_filename)
1433
+ # If eq is custom generated, we need to include the functions in globs
1434
+ globs = {}
1435
+
1436
+ hash_def = "def __hash__(self"
1437
+ hash_func = "hash(("
1438
+ closing_braces = "))"
1439
+ if not cache_hash:
1440
+ hash_def += "):"
1441
+ else:
1442
+ hash_def += ", *"
1443
+
1444
+ hash_def += ", _cache_wrapper=__import__('attr._make')._make._CacheHashWrapper):"
1445
+ hash_func = "_cache_wrapper(" + hash_func
1446
+ closing_braces += ")"
1447
+
1448
+ method_lines = [hash_def]
1449
+
1450
+ def append_hash_computation_lines(prefix, indent):
1451
+ """
1452
+ Generate the code for actually computing the hash code.
1453
+ Below this will either be returned directly or used to compute
1454
+ a value which is then cached, depending on the value of cache_hash
1455
+ """
1456
+
1457
+ method_lines.extend(
1458
+ [
1459
+ indent + prefix + hash_func,
1460
+ indent + f" {type_hash},",
1461
+ ]
1462
+ )
1463
+
1464
+ for a in attrs:
1465
+ if a.eq_key:
1466
+ cmp_name = f"_{a.name}_key"
1467
+ globs[cmp_name] = a.eq_key
1468
+ method_lines.append(
1469
+ indent + f" {cmp_name}(self.{a.name}),"
1470
+ )
1471
+ else:
1472
+ method_lines.append(indent + f" self.{a.name},")
1473
+
1474
+ method_lines.append(indent + " " + closing_braces)
1475
+
1476
+ if cache_hash:
1477
+ method_lines.append(tab + f"if self.{_HASH_CACHE_FIELD} is None:")
1478
+ if frozen:
1479
+ append_hash_computation_lines(
1480
+ f"object.__setattr__(self, '{_HASH_CACHE_FIELD}', ", tab * 2
1481
+ )
1482
+ method_lines.append(tab * 2 + ")") # close __setattr__
1483
+ else:
1484
+ append_hash_computation_lines(
1485
+ f"self.{_HASH_CACHE_FIELD} = ", tab * 2
1486
+ )
1487
+ method_lines.append(tab + f"return self.{_HASH_CACHE_FIELD}")
1488
+ else:
1489
+ append_hash_computation_lines("return ", tab)
1490
+
1491
+ script = "\n".join(method_lines)
1492
+ return _make_method("__hash__", script, unique_filename, globs)
1493
+
1494
+
1495
+ def _add_hash(cls, attrs):
1496
+ """
1497
+ Add a hash method to *cls*.
1498
+ """
1499
+ cls.__hash__ = _make_hash(cls, attrs, frozen=False, cache_hash=False)
1500
+ return cls
1501
+
1502
+
1503
+ def _make_ne():
1504
+ """
1505
+ Create __ne__ method.
1506
+ """
1507
+
1508
+ def __ne__(self, other):
1509
+ """
1510
+ Check equality and either forward a NotImplemented or
1511
+ return the result negated.
1512
+ """
1513
+ result = self.__eq__(other)
1514
+ if result is NotImplemented:
1515
+ return NotImplemented
1516
+
1517
+ return not result
1518
+
1519
+ return __ne__
1520
+
1521
+
1522
+ def _make_eq(cls, attrs):
1523
+ """
1524
+ Create __eq__ method for *cls* with *attrs*.
1525
+ """
1526
+ attrs = [a for a in attrs if a.eq]
1527
+
1528
+ unique_filename = _generate_unique_filename(cls, "eq")
1529
+ lines = [
1530
+ "def __eq__(self, other):",
1531
+ " if other.__class__ is not self.__class__:",
1532
+ " return NotImplemented",
1533
+ ]
1534
+
1535
+ # We can't just do a big self.x = other.x and... clause due to
1536
+ # irregularities like nan == nan is false but (nan,) == (nan,) is true.
1537
+ globs = {}
1538
+ if attrs:
1539
+ lines.append(" return (")
1540
+ for a in attrs:
1541
+ if a.eq_key:
1542
+ cmp_name = f"_{a.name}_key"
1543
+ # Add the key function to the global namespace
1544
+ # of the evaluated function.
1545
+ globs[cmp_name] = a.eq_key
1546
+ lines.append(
1547
+ f" {cmp_name}(self.{a.name}) == {cmp_name}(other.{a.name})"
1548
+ )
1549
+ else:
1550
+ lines.append(f" self.{a.name} == other.{a.name}")
1551
+ if a is not attrs[-1]:
1552
+ lines[-1] = f"{lines[-1]} and"
1553
+ lines.append(" )")
1554
+ else:
1555
+ lines.append(" return True")
1556
+
1557
+ script = "\n".join(lines)
1558
+
1559
+ return _make_method("__eq__", script, unique_filename, globs)
1560
+
1561
+
1562
+ def _make_order(cls, attrs):
1563
+ """
1564
+ Create ordering methods for *cls* with *attrs*.
1565
+ """
1566
+ attrs = [a for a in attrs if a.order]
1567
+
1568
+ def attrs_to_tuple(obj):
1569
+ """
1570
+ Save us some typing.
1571
+ """
1572
+ return tuple(
1573
+ key(value) if key else value
1574
+ for value, key in (
1575
+ (getattr(obj, a.name), a.order_key) for a in attrs
1576
+ )
1577
+ )
1578
+
1579
+ def __lt__(self, other):
1580
+ """
1581
+ Automatically created by attrs.
1582
+ """
1583
+ if other.__class__ is self.__class__:
1584
+ return attrs_to_tuple(self) < attrs_to_tuple(other)
1585
+
1586
+ return NotImplemented
1587
+
1588
+ def __le__(self, other):
1589
+ """
1590
+ Automatically created by attrs.
1591
+ """
1592
+ if other.__class__ is self.__class__:
1593
+ return attrs_to_tuple(self) <= attrs_to_tuple(other)
1594
+
1595
+ return NotImplemented
1596
+
1597
+ def __gt__(self, other):
1598
+ """
1599
+ Automatically created by attrs.
1600
+ """
1601
+ if other.__class__ is self.__class__:
1602
+ return attrs_to_tuple(self) > attrs_to_tuple(other)
1603
+
1604
+ return NotImplemented
1605
+
1606
+ def __ge__(self, other):
1607
+ """
1608
+ Automatically created by attrs.
1609
+ """
1610
+ if other.__class__ is self.__class__:
1611
+ return attrs_to_tuple(self) >= attrs_to_tuple(other)
1612
+
1613
+ return NotImplemented
1614
+
1615
+ return __lt__, __le__, __gt__, __ge__
1616
+
1617
+
1618
+ def _add_eq(cls, attrs=None):
1619
+ """
1620
+ Add equality methods to *cls* with *attrs*.
1621
+ """
1622
+ if attrs is None:
1623
+ attrs = cls.__attrs_attrs__
1624
+
1625
+ cls.__eq__ = _make_eq(cls, attrs)
1626
+ cls.__ne__ = _make_ne()
1627
+
1628
+ return cls
1629
+
1630
+
1631
+ def _make_repr(attrs, ns, cls):
1632
+ unique_filename = _generate_unique_filename(cls, "repr")
1633
+ # Figure out which attributes to include, and which function to use to
1634
+ # format them. The a.repr value can be either bool or a custom
1635
+ # callable.
1636
+ attr_names_with_reprs = tuple(
1637
+ (a.name, (repr if a.repr is True else a.repr), a.init)
1638
+ for a in attrs
1639
+ if a.repr is not False
1640
+ )
1641
+ globs = {
1642
+ name + "_repr": r for name, r, _ in attr_names_with_reprs if r != repr
1643
+ }
1644
+ globs["_compat"] = _compat
1645
+ globs["AttributeError"] = AttributeError
1646
+ globs["NOTHING"] = NOTHING
1647
+ attribute_fragments = []
1648
+ for name, r, i in attr_names_with_reprs:
1649
+ accessor = (
1650
+ "self." + name if i else 'getattr(self, "' + name + '", NOTHING)'
1651
+ )
1652
+ fragment = (
1653
+ "%s={%s!r}" % (name, accessor)
1654
+ if r == repr
1655
+ else "%s={%s_repr(%s)}" % (name, name, accessor)
1656
+ )
1657
+ attribute_fragments.append(fragment)
1658
+ repr_fragment = ", ".join(attribute_fragments)
1659
+
1660
+ if ns is None:
1661
+ cls_name_fragment = '{self.__class__.__qualname__.rsplit(">.", 1)[-1]}'
1662
+ else:
1663
+ cls_name_fragment = ns + ".{self.__class__.__name__}"
1664
+
1665
+ lines = [
1666
+ "def __repr__(self):",
1667
+ " try:",
1668
+ " already_repring = _compat.repr_context.already_repring",
1669
+ " except AttributeError:",
1670
+ " already_repring = {id(self),}",
1671
+ " _compat.repr_context.already_repring = already_repring",
1672
+ " else:",
1673
+ " if id(self) in already_repring:",
1674
+ " return '...'",
1675
+ " else:",
1676
+ " already_repring.add(id(self))",
1677
+ " try:",
1678
+ f" return f'{cls_name_fragment}({repr_fragment})'",
1679
+ " finally:",
1680
+ " already_repring.remove(id(self))",
1681
+ ]
1682
+
1683
+ return _make_method(
1684
+ "__repr__", "\n".join(lines), unique_filename, globs=globs
1685
+ )
1686
+
1687
+
1688
+ def _add_repr(cls, ns=None, attrs=None):
1689
+ """
1690
+ Add a repr method to *cls*.
1691
+ """
1692
+ if attrs is None:
1693
+ attrs = cls.__attrs_attrs__
1694
+
1695
+ cls.__repr__ = _make_repr(attrs, ns, cls)
1696
+ return cls
1697
+
1698
+
1699
+ def fields(cls):
1700
+ """
1701
+ Return the tuple of *attrs* attributes for a class.
1702
+
1703
+ The tuple also allows accessing the fields by their names (see below for
1704
+ examples).
1705
+
1706
+ Args:
1707
+ cls (type): Class to introspect.
1708
+
1709
+ Raises:
1710
+ TypeError: If *cls* is not a class.
1711
+
1712
+ attrs.exceptions.NotAnAttrsClassError:
1713
+ If *cls* is not an *attrs* class.
1714
+
1715
+ Returns:
1716
+ tuple (with name accessors) of `attrs.Attribute`
1717
+
1718
+ .. versionchanged:: 16.2.0 Returned tuple allows accessing the fields
1719
+ by name.
1720
+ .. versionchanged:: 23.1.0 Add support for generic classes.
1721
+ """
1722
+ generic_base = get_generic_base(cls)
1723
+
1724
+ if generic_base is None and not isinstance(cls, type):
1725
+ msg = "Passed object must be a class."
1726
+ raise TypeError(msg)
1727
+
1728
+ attrs = getattr(cls, "__attrs_attrs__", None)
1729
+
1730
+ if attrs is None:
1731
+ if generic_base is not None:
1732
+ attrs = getattr(generic_base, "__attrs_attrs__", None)
1733
+ if attrs is not None:
1734
+ # Even though this is global state, stick it on here to speed
1735
+ # it up. We rely on `cls` being cached for this to be
1736
+ # efficient.
1737
+ cls.__attrs_attrs__ = attrs
1738
+ return attrs
1739
+ msg = f"{cls!r} is not an attrs-decorated class."
1740
+ raise NotAnAttrsClassError(msg)
1741
+
1742
+ return attrs
1743
+
1744
+
1745
+ def fields_dict(cls):
1746
+ """
1747
+ Return an ordered dictionary of *attrs* attributes for a class, whose keys
1748
+ are the attribute names.
1749
+
1750
+ Args:
1751
+ cls (type): Class to introspect.
1752
+
1753
+ Raises:
1754
+ TypeError: If *cls* is not a class.
1755
+
1756
+ attrs.exceptions.NotAnAttrsClassError:
1757
+ If *cls* is not an *attrs* class.
1758
+
1759
+ Returns:
1760
+ dict[str, attrs.Attribute]: Dict of attribute name to definition
1761
+
1762
+ .. versionadded:: 18.1.0
1763
+ """
1764
+ if not isinstance(cls, type):
1765
+ msg = "Passed object must be a class."
1766
+ raise TypeError(msg)
1767
+ attrs = getattr(cls, "__attrs_attrs__", None)
1768
+ if attrs is None:
1769
+ msg = f"{cls!r} is not an attrs-decorated class."
1770
+ raise NotAnAttrsClassError(msg)
1771
+ return {a.name: a for a in attrs}
1772
+
1773
+
1774
+ def validate(inst):
1775
+ """
1776
+ Validate all attributes on *inst* that have a validator.
1777
+
1778
+ Leaves all exceptions through.
1779
+
1780
+ Args:
1781
+ inst: Instance of a class with *attrs* attributes.
1782
+ """
1783
+ if _config._run_validators is False:
1784
+ return
1785
+
1786
+ for a in fields(inst.__class__):
1787
+ v = a.validator
1788
+ if v is not None:
1789
+ v(inst, a, getattr(inst, a.name))
1790
+
1791
+
1792
+ def _is_slot_attr(a_name, base_attr_map):
1793
+ """
1794
+ Check if the attribute name comes from a slot class.
1795
+ """
1796
+ cls = base_attr_map.get(a_name)
1797
+ return cls and "__slots__" in cls.__dict__
1798
+
1799
+
1800
+ def _make_init(
1801
+ cls,
1802
+ attrs,
1803
+ pre_init,
1804
+ pre_init_has_args,
1805
+ post_init,
1806
+ frozen,
1807
+ slots,
1808
+ cache_hash,
1809
+ base_attr_map,
1810
+ is_exc,
1811
+ cls_on_setattr,
1812
+ attrs_init,
1813
+ ):
1814
+ has_cls_on_setattr = (
1815
+ cls_on_setattr is not None and cls_on_setattr is not setters.NO_OP
1816
+ )
1817
+
1818
+ if frozen and has_cls_on_setattr:
1819
+ msg = "Frozen classes can't use on_setattr."
1820
+ raise ValueError(msg)
1821
+
1822
+ needs_cached_setattr = cache_hash or frozen
1823
+ filtered_attrs = []
1824
+ attr_dict = {}
1825
+ for a in attrs:
1826
+ if not a.init and a.default is NOTHING:
1827
+ continue
1828
+
1829
+ filtered_attrs.append(a)
1830
+ attr_dict[a.name] = a
1831
+
1832
+ if a.on_setattr is not None:
1833
+ if frozen is True:
1834
+ msg = "Frozen classes can't use on_setattr."
1835
+ raise ValueError(msg)
1836
+
1837
+ needs_cached_setattr = True
1838
+ elif has_cls_on_setattr and a.on_setattr is not setters.NO_OP:
1839
+ needs_cached_setattr = True
1840
+
1841
+ unique_filename = _generate_unique_filename(cls, "init")
1842
+
1843
+ script, globs, annotations = _attrs_to_init_script(
1844
+ filtered_attrs,
1845
+ frozen,
1846
+ slots,
1847
+ pre_init,
1848
+ pre_init_has_args,
1849
+ post_init,
1850
+ cache_hash,
1851
+ base_attr_map,
1852
+ is_exc,
1853
+ needs_cached_setattr,
1854
+ has_cls_on_setattr,
1855
+ "__attrs_init__" if attrs_init else "__init__",
1856
+ )
1857
+ if cls.__module__ in sys.modules:
1858
+ # This makes typing.get_type_hints(CLS.__init__) resolve string types.
1859
+ globs.update(sys.modules[cls.__module__].__dict__)
1860
+
1861
+ globs.update({"NOTHING": NOTHING, "attr_dict": attr_dict})
1862
+
1863
+ if needs_cached_setattr:
1864
+ # Save the lookup overhead in __init__ if we need to circumvent
1865
+ # setattr hooks.
1866
+ globs["_cached_setattr_get"] = _OBJ_SETATTR.__get__
1867
+
1868
+ init = _make_method(
1869
+ "__attrs_init__" if attrs_init else "__init__",
1870
+ script,
1871
+ unique_filename,
1872
+ globs,
1873
+ )
1874
+ init.__annotations__ = annotations
1875
+
1876
+ return init
1877
+
1878
+
1879
+ def _setattr(attr_name: str, value_var: str, has_on_setattr: bool) -> str:
1880
+ """
1881
+ Use the cached object.setattr to set *attr_name* to *value_var*.
1882
+ """
1883
+ return f"_setattr('{attr_name}', {value_var})"
1884
+
1885
+
1886
+ def _setattr_with_converter(
1887
+ attr_name: str, value_var: str, has_on_setattr: bool, converter: Converter
1888
+ ) -> str:
1889
+ """
1890
+ Use the cached object.setattr to set *attr_name* to *value_var*, but run
1891
+ its converter first.
1892
+ """
1893
+ return f"_setattr('{attr_name}', {converter._fmt_converter_call(attr_name, value_var)})"
1894
+
1895
+
1896
+ def _assign(attr_name: str, value: str, has_on_setattr: bool) -> str:
1897
+ """
1898
+ Unless *attr_name* has an on_setattr hook, use normal assignment. Otherwise
1899
+ relegate to _setattr.
1900
+ """
1901
+ if has_on_setattr:
1902
+ return _setattr(attr_name, value, True)
1903
+
1904
+ return f"self.{attr_name} = {value}"
1905
+
1906
+
1907
+ def _assign_with_converter(
1908
+ attr_name: str, value_var: str, has_on_setattr: bool, converter: Converter
1909
+ ) -> str:
1910
+ """
1911
+ Unless *attr_name* has an on_setattr hook, use normal assignment after
1912
+ conversion. Otherwise relegate to _setattr_with_converter.
1913
+ """
1914
+ if has_on_setattr:
1915
+ return _setattr_with_converter(attr_name, value_var, True, converter)
1916
+
1917
+ return f"self.{attr_name} = {converter._fmt_converter_call(attr_name, value_var)}"
1918
+
1919
+
1920
+ def _determine_setters(
1921
+ frozen: bool, slots: bool, base_attr_map: dict[str, type]
1922
+ ):
1923
+ """
1924
+ Determine the correct setter functions based on whether a class is frozen
1925
+ and/or slotted.
1926
+ """
1927
+ if frozen is True:
1928
+ if slots is True:
1929
+ return (), _setattr, _setattr_with_converter
1930
+
1931
+ # Dict frozen classes assign directly to __dict__.
1932
+ # But only if the attribute doesn't come from an ancestor slot
1933
+ # class.
1934
+ # Note _inst_dict will be used again below if cache_hash is True
1935
+
1936
+ def fmt_setter(
1937
+ attr_name: str, value_var: str, has_on_setattr: bool
1938
+ ) -> str:
1939
+ if _is_slot_attr(attr_name, base_attr_map):
1940
+ return _setattr(attr_name, value_var, has_on_setattr)
1941
+
1942
+ return f"_inst_dict['{attr_name}'] = {value_var}"
1943
+
1944
+ def fmt_setter_with_converter(
1945
+ attr_name: str,
1946
+ value_var: str,
1947
+ has_on_setattr: bool,
1948
+ converter: Converter,
1949
+ ) -> str:
1950
+ if has_on_setattr or _is_slot_attr(attr_name, base_attr_map):
1951
+ return _setattr_with_converter(
1952
+ attr_name, value_var, has_on_setattr, converter
1953
+ )
1954
+
1955
+ return f"_inst_dict['{attr_name}'] = {converter._fmt_converter_call(attr_name, value_var)}"
1956
+
1957
+ return (
1958
+ ("_inst_dict = self.__dict__",),
1959
+ fmt_setter,
1960
+ fmt_setter_with_converter,
1961
+ )
1962
+
1963
+ # Not frozen -- we can just assign directly.
1964
+ return (), _assign, _assign_with_converter
1965
+
1966
+
1967
+ def _attrs_to_init_script(
1968
+ attrs: list[Attribute],
1969
+ is_frozen: bool,
1970
+ is_slotted: bool,
1971
+ call_pre_init: bool,
1972
+ pre_init_has_args: bool,
1973
+ call_post_init: bool,
1974
+ does_cache_hash: bool,
1975
+ base_attr_map: dict[str, type],
1976
+ is_exc: bool,
1977
+ needs_cached_setattr: bool,
1978
+ has_cls_on_setattr: bool,
1979
+ method_name: str,
1980
+ ) -> tuple[str, dict, dict]:
1981
+ """
1982
+ Return a script of an initializer for *attrs*, a dict of globals, and
1983
+ annotations for the initializer.
1984
+
1985
+ The globals are required by the generated script.
1986
+ """
1987
+ lines = ["self.__attrs_pre_init__()"] if call_pre_init else []
1988
+
1989
+ if needs_cached_setattr:
1990
+ lines.append(
1991
+ # Circumvent the __setattr__ descriptor to save one lookup per
1992
+ # assignment. Note _setattr will be used again below if
1993
+ # does_cache_hash is True.
1994
+ "_setattr = _cached_setattr_get(self)"
1995
+ )
1996
+
1997
+ extra_lines, fmt_setter, fmt_setter_with_converter = _determine_setters(
1998
+ is_frozen, is_slotted, base_attr_map
1999
+ )
2000
+ lines.extend(extra_lines)
2001
+
2002
+ args = []
2003
+ kw_only_args = []
2004
+ attrs_to_validate = []
2005
+
2006
+ # This is a dictionary of names to validator and converter callables.
2007
+ # Injecting this into __init__ globals lets us avoid lookups.
2008
+ names_for_globals = {}
2009
+ annotations = {"return": None}
2010
+
2011
+ for a in attrs:
2012
+ if a.validator:
2013
+ attrs_to_validate.append(a)
2014
+
2015
+ attr_name = a.name
2016
+ has_on_setattr = a.on_setattr is not None or (
2017
+ a.on_setattr is not setters.NO_OP and has_cls_on_setattr
2018
+ )
2019
+ # a.alias is set to maybe-mangled attr_name in _ClassBuilder if not
2020
+ # explicitly provided
2021
+ arg_name = a.alias
2022
+
2023
+ has_factory = isinstance(a.default, Factory)
2024
+ maybe_self = "self" if has_factory and a.default.takes_self else ""
2025
+
2026
+ if a.converter and not isinstance(a.converter, Converter):
2027
+ converter = Converter(a.converter)
2028
+ else:
2029
+ converter = a.converter
2030
+
2031
+ if a.init is False:
2032
+ if has_factory:
2033
+ init_factory_name = _INIT_FACTORY_PAT % (a.name,)
2034
+ if converter is not None:
2035
+ lines.append(
2036
+ fmt_setter_with_converter(
2037
+ attr_name,
2038
+ init_factory_name + f"({maybe_self})",
2039
+ has_on_setattr,
2040
+ converter,
2041
+ )
2042
+ )
2043
+ names_for_globals[converter._get_global_name(a.name)] = (
2044
+ converter.converter
2045
+ )
2046
+ else:
2047
+ lines.append(
2048
+ fmt_setter(
2049
+ attr_name,
2050
+ init_factory_name + f"({maybe_self})",
2051
+ has_on_setattr,
2052
+ )
2053
+ )
2054
+ names_for_globals[init_factory_name] = a.default.factory
2055
+ elif converter is not None:
2056
+ lines.append(
2057
+ fmt_setter_with_converter(
2058
+ attr_name,
2059
+ f"attr_dict['{attr_name}'].default",
2060
+ has_on_setattr,
2061
+ converter,
2062
+ )
2063
+ )
2064
+ names_for_globals[converter._get_global_name(a.name)] = (
2065
+ converter.converter
2066
+ )
2067
+ else:
2068
+ lines.append(
2069
+ fmt_setter(
2070
+ attr_name,
2071
+ f"attr_dict['{attr_name}'].default",
2072
+ has_on_setattr,
2073
+ )
2074
+ )
2075
+ elif a.default is not NOTHING and not has_factory:
2076
+ arg = f"{arg_name}=attr_dict['{attr_name}'].default"
2077
+ if a.kw_only:
2078
+ kw_only_args.append(arg)
2079
+ else:
2080
+ args.append(arg)
2081
+
2082
+ if converter is not None:
2083
+ lines.append(
2084
+ fmt_setter_with_converter(
2085
+ attr_name, arg_name, has_on_setattr, converter
2086
+ )
2087
+ )
2088
+ names_for_globals[converter._get_global_name(a.name)] = (
2089
+ converter.converter
2090
+ )
2091
+ else:
2092
+ lines.append(fmt_setter(attr_name, arg_name, has_on_setattr))
2093
+
2094
+ elif has_factory:
2095
+ arg = f"{arg_name}=NOTHING"
2096
+ if a.kw_only:
2097
+ kw_only_args.append(arg)
2098
+ else:
2099
+ args.append(arg)
2100
+ lines.append(f"if {arg_name} is not NOTHING:")
2101
+
2102
+ init_factory_name = _INIT_FACTORY_PAT % (a.name,)
2103
+ if converter is not None:
2104
+ lines.append(
2105
+ " "
2106
+ + fmt_setter_with_converter(
2107
+ attr_name, arg_name, has_on_setattr, converter
2108
+ )
2109
+ )
2110
+ lines.append("else:")
2111
+ lines.append(
2112
+ " "
2113
+ + fmt_setter_with_converter(
2114
+ attr_name,
2115
+ init_factory_name + "(" + maybe_self + ")",
2116
+ has_on_setattr,
2117
+ converter,
2118
+ )
2119
+ )
2120
+ names_for_globals[converter._get_global_name(a.name)] = (
2121
+ converter.converter
2122
+ )
2123
+ else:
2124
+ lines.append(
2125
+ " " + fmt_setter(attr_name, arg_name, has_on_setattr)
2126
+ )
2127
+ lines.append("else:")
2128
+ lines.append(
2129
+ " "
2130
+ + fmt_setter(
2131
+ attr_name,
2132
+ init_factory_name + "(" + maybe_self + ")",
2133
+ has_on_setattr,
2134
+ )
2135
+ )
2136
+ names_for_globals[init_factory_name] = a.default.factory
2137
+ else:
2138
+ if a.kw_only:
2139
+ kw_only_args.append(arg_name)
2140
+ else:
2141
+ args.append(arg_name)
2142
+
2143
+ if converter is not None:
2144
+ lines.append(
2145
+ fmt_setter_with_converter(
2146
+ attr_name, arg_name, has_on_setattr, converter
2147
+ )
2148
+ )
2149
+ names_for_globals[converter._get_global_name(a.name)] = (
2150
+ converter.converter
2151
+ )
2152
+ else:
2153
+ lines.append(fmt_setter(attr_name, arg_name, has_on_setattr))
2154
+
2155
+ if a.init is True:
2156
+ if a.type is not None and converter is None:
2157
+ annotations[arg_name] = a.type
2158
+ elif converter is not None and converter._first_param_type:
2159
+ # Use the type from the converter if present.
2160
+ annotations[arg_name] = converter._first_param_type
2161
+
2162
+ if attrs_to_validate: # we can skip this if there are no validators.
2163
+ names_for_globals["_config"] = _config
2164
+ lines.append("if _config._run_validators is True:")
2165
+ for a in attrs_to_validate:
2166
+ val_name = "__attr_validator_" + a.name
2167
+ attr_name = "__attr_" + a.name
2168
+ lines.append(f" {val_name}(self, {attr_name}, self.{a.name})")
2169
+ names_for_globals[val_name] = a.validator
2170
+ names_for_globals[attr_name] = a
2171
+
2172
+ if call_post_init:
2173
+ lines.append("self.__attrs_post_init__()")
2174
+
2175
+ # Because this is set only after __attrs_post_init__ is called, a crash
2176
+ # will result if post-init tries to access the hash code. This seemed
2177
+ # preferable to setting this beforehand, in which case alteration to field
2178
+ # values during post-init combined with post-init accessing the hash code
2179
+ # would result in silent bugs.
2180
+ if does_cache_hash:
2181
+ if is_frozen:
2182
+ if is_slotted:
2183
+ init_hash_cache = f"_setattr('{_HASH_CACHE_FIELD}', None)"
2184
+ else:
2185
+ init_hash_cache = f"_inst_dict['{_HASH_CACHE_FIELD}'] = None"
2186
+ else:
2187
+ init_hash_cache = f"self.{_HASH_CACHE_FIELD} = None"
2188
+ lines.append(init_hash_cache)
2189
+
2190
+ # For exceptions we rely on BaseException.__init__ for proper
2191
+ # initialization.
2192
+ if is_exc:
2193
+ vals = ",".join(f"self.{a.name}" for a in attrs if a.init)
2194
+
2195
+ lines.append(f"BaseException.__init__(self, {vals})")
2196
+
2197
+ args = ", ".join(args)
2198
+ pre_init_args = args
2199
+ if kw_only_args:
2200
+ # leading comma & kw_only args
2201
+ args += f"{', ' if args else ''}*, {', '.join(kw_only_args)}"
2202
+ pre_init_kw_only_args = ", ".join(
2203
+ [
2204
+ f"{kw_arg_name}={kw_arg_name}"
2205
+ # We need to remove the defaults from the kw_only_args.
2206
+ for kw_arg_name in (kwa.split("=")[0] for kwa in kw_only_args)
2207
+ ]
2208
+ )
2209
+ pre_init_args += ", " if pre_init_args else ""
2210
+ pre_init_args += pre_init_kw_only_args
2211
+
2212
+ if call_pre_init and pre_init_has_args:
2213
+ # If pre init method has arguments, pass same arguments as `__init__`.
2214
+ lines[0] = f"self.__attrs_pre_init__({pre_init_args})"
2215
+
2216
+ # Python 3.7 doesn't allow backslashes in f strings.
2217
+ NL = "\n "
2218
+ return (
2219
+ f"""def {method_name}(self, {args}):
2220
+ {NL.join(lines) if lines else 'pass'}
2221
+ """,
2222
+ names_for_globals,
2223
+ annotations,
2224
+ )
2225
+
2226
+
2227
+ def _default_init_alias_for(name: str) -> str:
2228
+ """
2229
+ The default __init__ parameter name for a field.
2230
+
2231
+ This performs private-name adjustment via leading-unscore stripping,
2232
+ and is the default value of Attribute.alias if not provided.
2233
+ """
2234
+
2235
+ return name.lstrip("_")
2236
+
2237
+
2238
+ class Attribute:
2239
+ """
2240
+ *Read-only* representation of an attribute.
2241
+
2242
+ .. warning::
2243
+
2244
+ You should never instantiate this class yourself.
2245
+
2246
+ The class has *all* arguments of `attr.ib` (except for ``factory`` which is
2247
+ only syntactic sugar for ``default=Factory(...)`` plus the following:
2248
+
2249
+ - ``name`` (`str`): The name of the attribute.
2250
+ - ``alias`` (`str`): The __init__ parameter name of the attribute, after
2251
+ any explicit overrides and default private-attribute-name handling.
2252
+ - ``inherited`` (`bool`): Whether or not that attribute has been inherited
2253
+ from a base class.
2254
+ - ``eq_key`` and ``order_key`` (`typing.Callable` or `None`): The
2255
+ callables that are used for comparing and ordering objects by this
2256
+ attribute, respectively. These are set by passing a callable to
2257
+ `attr.ib`'s ``eq``, ``order``, or ``cmp`` arguments. See also
2258
+ :ref:`comparison customization <custom-comparison>`.
2259
+
2260
+ Instances of this class are frequently used for introspection purposes
2261
+ like:
2262
+
2263
+ - `fields` returns a tuple of them.
2264
+ - Validators get them passed as the first argument.
2265
+ - The :ref:`field transformer <transform-fields>` hook receives a list of
2266
+ them.
2267
+ - The ``alias`` property exposes the __init__ parameter name of the field,
2268
+ with any overrides and default private-attribute handling applied.
2269
+
2270
+
2271
+ .. versionadded:: 20.1.0 *inherited*
2272
+ .. versionadded:: 20.1.0 *on_setattr*
2273
+ .. versionchanged:: 20.2.0 *inherited* is not taken into account for
2274
+ equality checks and hashing anymore.
2275
+ .. versionadded:: 21.1.0 *eq_key* and *order_key*
2276
+ .. versionadded:: 22.2.0 *alias*
2277
+
2278
+ For the full version history of the fields, see `attr.ib`.
2279
+ """
2280
+
2281
+ __slots__ = (
2282
+ "name",
2283
+ "default",
2284
+ "validator",
2285
+ "repr",
2286
+ "eq",
2287
+ "eq_key",
2288
+ "order",
2289
+ "order_key",
2290
+ "hash",
2291
+ "init",
2292
+ "metadata",
2293
+ "type",
2294
+ "converter",
2295
+ "kw_only",
2296
+ "inherited",
2297
+ "on_setattr",
2298
+ "alias",
2299
+ )
2300
+
2301
+ def __init__(
2302
+ self,
2303
+ name,
2304
+ default,
2305
+ validator,
2306
+ repr,
2307
+ cmp, # XXX: unused, remove along with other cmp code.
2308
+ hash,
2309
+ init,
2310
+ inherited,
2311
+ metadata=None,
2312
+ type=None,
2313
+ converter=None,
2314
+ kw_only=False,
2315
+ eq=None,
2316
+ eq_key=None,
2317
+ order=None,
2318
+ order_key=None,
2319
+ on_setattr=None,
2320
+ alias=None,
2321
+ ):
2322
+ eq, eq_key, order, order_key = _determine_attrib_eq_order(
2323
+ cmp, eq_key or eq, order_key or order, True
2324
+ )
2325
+
2326
+ # Cache this descriptor here to speed things up later.
2327
+ bound_setattr = _OBJ_SETATTR.__get__(self)
2328
+
2329
+ # Despite the big red warning, people *do* instantiate `Attribute`
2330
+ # themselves.
2331
+ bound_setattr("name", name)
2332
+ bound_setattr("default", default)
2333
+ bound_setattr("validator", validator)
2334
+ bound_setattr("repr", repr)
2335
+ bound_setattr("eq", eq)
2336
+ bound_setattr("eq_key", eq_key)
2337
+ bound_setattr("order", order)
2338
+ bound_setattr("order_key", order_key)
2339
+ bound_setattr("hash", hash)
2340
+ bound_setattr("init", init)
2341
+ bound_setattr("converter", converter)
2342
+ bound_setattr(
2343
+ "metadata",
2344
+ (
2345
+ types.MappingProxyType(dict(metadata)) # Shallow copy
2346
+ if metadata
2347
+ else _EMPTY_METADATA_SINGLETON
2348
+ ),
2349
+ )
2350
+ bound_setattr("type", type)
2351
+ bound_setattr("kw_only", kw_only)
2352
+ bound_setattr("inherited", inherited)
2353
+ bound_setattr("on_setattr", on_setattr)
2354
+ bound_setattr("alias", alias)
2355
+
2356
+ def __setattr__(self, name, value):
2357
+ raise FrozenInstanceError()
2358
+
2359
+ @classmethod
2360
+ def from_counting_attr(cls, name, ca, type=None):
2361
+ # type holds the annotated value. deal with conflicts:
2362
+ if type is None:
2363
+ type = ca.type
2364
+ elif ca.type is not None:
2365
+ msg = "Type annotation and type argument cannot both be present"
2366
+ raise ValueError(msg)
2367
+ inst_dict = {
2368
+ k: getattr(ca, k)
2369
+ for k in Attribute.__slots__
2370
+ if k
2371
+ not in (
2372
+ "name",
2373
+ "validator",
2374
+ "default",
2375
+ "type",
2376
+ "inherited",
2377
+ ) # exclude methods and deprecated alias
2378
+ }
2379
+ return cls(
2380
+ name=name,
2381
+ validator=ca._validator,
2382
+ default=ca._default,
2383
+ type=type,
2384
+ cmp=None,
2385
+ inherited=False,
2386
+ **inst_dict,
2387
+ )
2388
+
2389
+ # Don't use attrs.evolve since fields(Attribute) doesn't work
2390
+ def evolve(self, **changes):
2391
+ """
2392
+ Copy *self* and apply *changes*.
2393
+
2394
+ This works similarly to `attrs.evolve` but that function does not work
2395
+ with {class}`Attribute`.
2396
+
2397
+ It is mainly meant to be used for `transform-fields`.
2398
+
2399
+ .. versionadded:: 20.3.0
2400
+ """
2401
+ new = copy.copy(self)
2402
+
2403
+ new._setattrs(changes.items())
2404
+
2405
+ return new
2406
+
2407
+ # Don't use _add_pickle since fields(Attribute) doesn't work
2408
+ def __getstate__(self):
2409
+ """
2410
+ Play nice with pickle.
2411
+ """
2412
+ return tuple(
2413
+ getattr(self, name) if name != "metadata" else dict(self.metadata)
2414
+ for name in self.__slots__
2415
+ )
2416
+
2417
+ def __setstate__(self, state):
2418
+ """
2419
+ Play nice with pickle.
2420
+ """
2421
+ self._setattrs(zip(self.__slots__, state))
2422
+
2423
+ def _setattrs(self, name_values_pairs):
2424
+ bound_setattr = _OBJ_SETATTR.__get__(self)
2425
+ for name, value in name_values_pairs:
2426
+ if name != "metadata":
2427
+ bound_setattr(name, value)
2428
+ else:
2429
+ bound_setattr(
2430
+ name,
2431
+ (
2432
+ types.MappingProxyType(dict(value))
2433
+ if value
2434
+ else _EMPTY_METADATA_SINGLETON
2435
+ ),
2436
+ )
2437
+
2438
+
2439
+ _a = [
2440
+ Attribute(
2441
+ name=name,
2442
+ default=NOTHING,
2443
+ validator=None,
2444
+ repr=True,
2445
+ cmp=None,
2446
+ eq=True,
2447
+ order=False,
2448
+ hash=(name != "metadata"),
2449
+ init=True,
2450
+ inherited=False,
2451
+ alias=_default_init_alias_for(name),
2452
+ )
2453
+ for name in Attribute.__slots__
2454
+ ]
2455
+
2456
+ Attribute = _add_hash(
2457
+ _add_eq(
2458
+ _add_repr(Attribute, attrs=_a),
2459
+ attrs=[a for a in _a if a.name != "inherited"],
2460
+ ),
2461
+ attrs=[a for a in _a if a.hash and a.name != "inherited"],
2462
+ )
2463
+
2464
+
2465
+ class _CountingAttr:
2466
+ """
2467
+ Intermediate representation of attributes that uses a counter to preserve
2468
+ the order in which the attributes have been defined.
2469
+
2470
+ *Internal* data structure of the attrs library. Running into is most
2471
+ likely the result of a bug like a forgotten `@attr.s` decorator.
2472
+ """
2473
+
2474
+ __slots__ = (
2475
+ "counter",
2476
+ "_default",
2477
+ "repr",
2478
+ "eq",
2479
+ "eq_key",
2480
+ "order",
2481
+ "order_key",
2482
+ "hash",
2483
+ "init",
2484
+ "metadata",
2485
+ "_validator",
2486
+ "converter",
2487
+ "type",
2488
+ "kw_only",
2489
+ "on_setattr",
2490
+ "alias",
2491
+ )
2492
+ __attrs_attrs__ = (
2493
+ *tuple(
2494
+ Attribute(
2495
+ name=name,
2496
+ alias=_default_init_alias_for(name),
2497
+ default=NOTHING,
2498
+ validator=None,
2499
+ repr=True,
2500
+ cmp=None,
2501
+ hash=True,
2502
+ init=True,
2503
+ kw_only=False,
2504
+ eq=True,
2505
+ eq_key=None,
2506
+ order=False,
2507
+ order_key=None,
2508
+ inherited=False,
2509
+ on_setattr=None,
2510
+ )
2511
+ for name in (
2512
+ "counter",
2513
+ "_default",
2514
+ "repr",
2515
+ "eq",
2516
+ "order",
2517
+ "hash",
2518
+ "init",
2519
+ "on_setattr",
2520
+ "alias",
2521
+ )
2522
+ ),
2523
+ Attribute(
2524
+ name="metadata",
2525
+ alias="metadata",
2526
+ default=None,
2527
+ validator=None,
2528
+ repr=True,
2529
+ cmp=None,
2530
+ hash=False,
2531
+ init=True,
2532
+ kw_only=False,
2533
+ eq=True,
2534
+ eq_key=None,
2535
+ order=False,
2536
+ order_key=None,
2537
+ inherited=False,
2538
+ on_setattr=None,
2539
+ ),
2540
+ )
2541
+ cls_counter = 0
2542
+
2543
+ def __init__(
2544
+ self,
2545
+ default,
2546
+ validator,
2547
+ repr,
2548
+ cmp,
2549
+ hash,
2550
+ init,
2551
+ converter,
2552
+ metadata,
2553
+ type,
2554
+ kw_only,
2555
+ eq,
2556
+ eq_key,
2557
+ order,
2558
+ order_key,
2559
+ on_setattr,
2560
+ alias,
2561
+ ):
2562
+ _CountingAttr.cls_counter += 1
2563
+ self.counter = _CountingAttr.cls_counter
2564
+ self._default = default
2565
+ self._validator = validator
2566
+ self.converter = converter
2567
+ self.repr = repr
2568
+ self.eq = eq
2569
+ self.eq_key = eq_key
2570
+ self.order = order
2571
+ self.order_key = order_key
2572
+ self.hash = hash
2573
+ self.init = init
2574
+ self.metadata = metadata
2575
+ self.type = type
2576
+ self.kw_only = kw_only
2577
+ self.on_setattr = on_setattr
2578
+ self.alias = alias
2579
+
2580
+ def validator(self, meth):
2581
+ """
2582
+ Decorator that adds *meth* to the list of validators.
2583
+
2584
+ Returns *meth* unchanged.
2585
+
2586
+ .. versionadded:: 17.1.0
2587
+ """
2588
+ if self._validator is None:
2589
+ self._validator = meth
2590
+ else:
2591
+ self._validator = and_(self._validator, meth)
2592
+ return meth
2593
+
2594
+ def default(self, meth):
2595
+ """
2596
+ Decorator that allows to set the default for an attribute.
2597
+
2598
+ Returns *meth* unchanged.
2599
+
2600
+ Raises:
2601
+ DefaultAlreadySetError: If default has been set before.
2602
+
2603
+ .. versionadded:: 17.1.0
2604
+ """
2605
+ if self._default is not NOTHING:
2606
+ raise DefaultAlreadySetError()
2607
+
2608
+ self._default = Factory(meth, takes_self=True)
2609
+
2610
+ return meth
2611
+
2612
+
2613
+ _CountingAttr = _add_eq(_add_repr(_CountingAttr))
2614
+
2615
+
2616
+ class Factory:
2617
+ """
2618
+ Stores a factory callable.
2619
+
2620
+ If passed as the default value to `attrs.field`, the factory is used to
2621
+ generate a new value.
2622
+
2623
+ Args:
2624
+ factory (typing.Callable):
2625
+ A callable that takes either none or exactly one mandatory
2626
+ positional argument depending on *takes_self*.
2627
+
2628
+ takes_self (bool):
2629
+ Pass the partially initialized instance that is being initialized
2630
+ as a positional argument.
2631
+
2632
+ .. versionadded:: 17.1.0 *takes_self*
2633
+ """
2634
+
2635
+ __slots__ = ("factory", "takes_self")
2636
+
2637
+ def __init__(self, factory, takes_self=False):
2638
+ self.factory = factory
2639
+ self.takes_self = takes_self
2640
+
2641
+ def __getstate__(self):
2642
+ """
2643
+ Play nice with pickle.
2644
+ """
2645
+ return tuple(getattr(self, name) for name in self.__slots__)
2646
+
2647
+ def __setstate__(self, state):
2648
+ """
2649
+ Play nice with pickle.
2650
+ """
2651
+ for name, value in zip(self.__slots__, state):
2652
+ setattr(self, name, value)
2653
+
2654
+
2655
+ _f = [
2656
+ Attribute(
2657
+ name=name,
2658
+ default=NOTHING,
2659
+ validator=None,
2660
+ repr=True,
2661
+ cmp=None,
2662
+ eq=True,
2663
+ order=False,
2664
+ hash=True,
2665
+ init=True,
2666
+ inherited=False,
2667
+ )
2668
+ for name in Factory.__slots__
2669
+ ]
2670
+
2671
+ Factory = _add_hash(_add_eq(_add_repr(Factory, attrs=_f), attrs=_f), attrs=_f)
2672
+
2673
+
2674
+ class Converter:
2675
+ """
2676
+ Stores a converter callable.
2677
+
2678
+ Allows for the wrapped converter to take additional arguments. The
2679
+ arguments are passed in the order they are documented.
2680
+
2681
+ Args:
2682
+ converter (Callable): A callable that converts the passed value.
2683
+
2684
+ takes_self (bool):
2685
+ Pass the partially initialized instance that is being initialized
2686
+ as a positional argument. (default: `False`)
2687
+
2688
+ takes_field (bool):
2689
+ Pass the field definition (an :class:`Attribute`) into the
2690
+ converter as a positional argument. (default: `False`)
2691
+
2692
+ .. versionadded:: 24.1.0
2693
+ """
2694
+
2695
+ __slots__ = (
2696
+ "converter",
2697
+ "takes_self",
2698
+ "takes_field",
2699
+ "_first_param_type",
2700
+ "_global_name",
2701
+ "__call__",
2702
+ )
2703
+
2704
+ def __init__(self, converter, *, takes_self=False, takes_field=False):
2705
+ self.converter = converter
2706
+ self.takes_self = takes_self
2707
+ self.takes_field = takes_field
2708
+
2709
+ ex = _AnnotationExtractor(converter)
2710
+ self._first_param_type = ex.get_first_param_type()
2711
+
2712
+ if not (self.takes_self or self.takes_field):
2713
+ self.__call__ = lambda value, _, __: self.converter(value)
2714
+ elif self.takes_self and not self.takes_field:
2715
+ self.__call__ = lambda value, instance, __: self.converter(
2716
+ value, instance
2717
+ )
2718
+ elif not self.takes_self and self.takes_field:
2719
+ self.__call__ = lambda value, __, field: self.converter(
2720
+ value, field
2721
+ )
2722
+ else:
2723
+ self.__call__ = lambda value, instance, field: self.converter(
2724
+ value, instance, field
2725
+ )
2726
+
2727
+ rt = ex.get_return_type()
2728
+ if rt is not None:
2729
+ self.__call__.__annotations__["return"] = rt
2730
+
2731
+ @staticmethod
2732
+ def _get_global_name(attr_name: str) -> str:
2733
+ """
2734
+ Return the name that a converter for an attribute name *attr_name*
2735
+ would have.
2736
+ """
2737
+ return f"__attr_converter_{attr_name}"
2738
+
2739
+ def _fmt_converter_call(self, attr_name: str, value_var: str) -> str:
2740
+ """
2741
+ Return a string that calls the converter for an attribute name
2742
+ *attr_name* and the value in variable named *value_var* according to
2743
+ `self.takes_self` and `self.takes_field`.
2744
+ """
2745
+ if not (self.takes_self or self.takes_field):
2746
+ return f"{self._get_global_name(attr_name)}({value_var})"
2747
+
2748
+ if self.takes_self and self.takes_field:
2749
+ return f"{self._get_global_name(attr_name)}({value_var}, self, attr_dict['{attr_name}'])"
2750
+
2751
+ if self.takes_self:
2752
+ return f"{self._get_global_name(attr_name)}({value_var}, self)"
2753
+
2754
+ return f"{self._get_global_name(attr_name)}({value_var}, attr_dict['{attr_name}'])"
2755
+
2756
+ def __getstate__(self):
2757
+ """
2758
+ Return a dict containing only converter and takes_self -- the rest gets
2759
+ computed when loading.
2760
+ """
2761
+ return {
2762
+ "converter": self.converter,
2763
+ "takes_self": self.takes_self,
2764
+ "takes_field": self.takes_field,
2765
+ }
2766
+
2767
+ def __setstate__(self, state):
2768
+ """
2769
+ Load instance from state.
2770
+ """
2771
+ self.__init__(**state)
2772
+
2773
+
2774
+ _f = [
2775
+ Attribute(
2776
+ name=name,
2777
+ default=NOTHING,
2778
+ validator=None,
2779
+ repr=True,
2780
+ cmp=None,
2781
+ eq=True,
2782
+ order=False,
2783
+ hash=True,
2784
+ init=True,
2785
+ inherited=False,
2786
+ )
2787
+ for name in ("converter", "takes_self", "takes_field")
2788
+ ]
2789
+
2790
+ Converter = _add_hash(
2791
+ _add_eq(_add_repr(Converter, attrs=_f), attrs=_f), attrs=_f
2792
+ )
2793
+
2794
+
2795
+ def make_class(
2796
+ name, attrs, bases=(object,), class_body=None, **attributes_arguments
2797
+ ):
2798
+ r"""
2799
+ A quick way to create a new class called *name* with *attrs*.
2800
+
2801
+ Args:
2802
+ name (str): The name for the new class.
2803
+
2804
+ attrs( list | dict):
2805
+ A list of names or a dictionary of mappings of names to `attr.ib`\
2806
+ s / `attrs.field`\ s.
2807
+
2808
+ The order is deduced from the order of the names or attributes
2809
+ inside *attrs*. Otherwise the order of the definition of the
2810
+ attributes is used.
2811
+
2812
+ bases (tuple[type, ...]): Classes that the new class will subclass.
2813
+
2814
+ class_body (dict):
2815
+ An optional dictionary of class attributes for the new class.
2816
+
2817
+ attributes_arguments: Passed unmodified to `attr.s`.
2818
+
2819
+ Returns:
2820
+ type: A new class with *attrs*.
2821
+
2822
+ .. versionadded:: 17.1.0 *bases*
2823
+ .. versionchanged:: 18.1.0 If *attrs* is ordered, the order is retained.
2824
+ .. versionchanged:: 23.2.0 *class_body*
2825
+ """
2826
+ if isinstance(attrs, dict):
2827
+ cls_dict = attrs
2828
+ elif isinstance(attrs, (list, tuple)):
2829
+ cls_dict = {a: attrib() for a in attrs}
2830
+ else:
2831
+ msg = "attrs argument must be a dict or a list."
2832
+ raise TypeError(msg)
2833
+
2834
+ pre_init = cls_dict.pop("__attrs_pre_init__", None)
2835
+ post_init = cls_dict.pop("__attrs_post_init__", None)
2836
+ user_init = cls_dict.pop("__init__", None)
2837
+
2838
+ body = {}
2839
+ if class_body is not None:
2840
+ body.update(class_body)
2841
+ if pre_init is not None:
2842
+ body["__attrs_pre_init__"] = pre_init
2843
+ if post_init is not None:
2844
+ body["__attrs_post_init__"] = post_init
2845
+ if user_init is not None:
2846
+ body["__init__"] = user_init
2847
+
2848
+ type_ = types.new_class(name, bases, {}, lambda ns: ns.update(body))
2849
+
2850
+ # For pickling to work, the __module__ variable needs to be set to the
2851
+ # frame where the class is created. Bypass this step in environments where
2852
+ # sys._getframe is not defined (Jython for example) or sys._getframe is not
2853
+ # defined for arguments greater than 0 (IronPython).
2854
+ with contextlib.suppress(AttributeError, ValueError):
2855
+ type_.__module__ = sys._getframe(1).f_globals.get(
2856
+ "__name__", "__main__"
2857
+ )
2858
+
2859
+ # We do it here for proper warnings with meaningful stacklevel.
2860
+ cmp = attributes_arguments.pop("cmp", None)
2861
+ (
2862
+ attributes_arguments["eq"],
2863
+ attributes_arguments["order"],
2864
+ ) = _determine_attrs_eq_order(
2865
+ cmp,
2866
+ attributes_arguments.get("eq"),
2867
+ attributes_arguments.get("order"),
2868
+ True,
2869
+ )
2870
+
2871
+ cls = _attrs(these=cls_dict, **attributes_arguments)(type_)
2872
+ # Only add type annotations now or "_attrs()" will complain:
2873
+ cls.__annotations__ = {
2874
+ k: v.type for k, v in cls_dict.items() if v.type is not None
2875
+ }
2876
+ return cls
2877
+
2878
+
2879
+ # These are required by within this module so we define them here and merely
2880
+ # import into .validators / .converters.
2881
+
2882
+
2883
+ @attrs(slots=True, unsafe_hash=True)
2884
+ class _AndValidator:
2885
+ """
2886
+ Compose many validators to a single one.
2887
+ """
2888
+
2889
+ _validators = attrib()
2890
+
2891
+ def __call__(self, inst, attr, value):
2892
+ for v in self._validators:
2893
+ v(inst, attr, value)
2894
+
2895
+
2896
+ def and_(*validators):
2897
+ """
2898
+ A validator that composes multiple validators into one.
2899
+
2900
+ When called on a value, it runs all wrapped validators.
2901
+
2902
+ Args:
2903
+ validators (~collections.abc.Iterable[typing.Callable]):
2904
+ Arbitrary number of validators.
2905
+
2906
+ .. versionadded:: 17.1.0
2907
+ """
2908
+ vals = []
2909
+ for validator in validators:
2910
+ vals.extend(
2911
+ validator._validators
2912
+ if isinstance(validator, _AndValidator)
2913
+ else [validator]
2914
+ )
2915
+
2916
+ return _AndValidator(tuple(vals))
2917
+
2918
+
2919
+ def pipe(*converters):
2920
+ """
2921
+ A converter that composes multiple converters into one.
2922
+
2923
+ When called on a value, it runs all wrapped converters, returning the
2924
+ *last* value.
2925
+
2926
+ Type annotations will be inferred from the wrapped converters', if they
2927
+ have any.
2928
+
2929
+ converters (~collections.abc.Iterable[typing.Callable]):
2930
+ Arbitrary number of converters.
2931
+
2932
+ .. versionadded:: 20.1.0
2933
+ """
2934
+
2935
+ def pipe_converter(val, inst, field):
2936
+ for c in converters:
2937
+ val = c(val, inst, field) if isinstance(c, Converter) else c(val)
2938
+
2939
+ return val
2940
+
2941
+ if not converters:
2942
+ # If the converter list is empty, pipe_converter is the identity.
2943
+ A = typing.TypeVar("A")
2944
+ pipe_converter.__annotations__.update({"val": A, "return": A})
2945
+ else:
2946
+ # Get parameter type from first converter.
2947
+ t = _AnnotationExtractor(converters[0]).get_first_param_type()
2948
+ if t:
2949
+ pipe_converter.__annotations__["val"] = t
2950
+
2951
+ last = converters[-1]
2952
+ if not PY_3_11_PLUS and isinstance(last, Converter):
2953
+ last = last.__call__
2954
+
2955
+ # Get return type from last converter.
2956
+ rt = _AnnotationExtractor(last).get_return_type()
2957
+ if rt:
2958
+ pipe_converter.__annotations__["return"] = rt
2959
+
2960
+ return Converter(pipe_converter, takes_self=True, takes_field=True)
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/_next_gen.py ADDED
@@ -0,0 +1,631 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ _DEFAULT_ON_SETATTR,
16
+ NOTHING,
17
+ _frozen_setattrs,
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
+ A class decorator that adds :term:`dunder methods` according to
50
+ :term:`fields <field>` specified using :doc:`type annotations <types>`,
51
+ `field()` calls, or the *these* argument.
52
+
53
+ Since *attrs* patches or replaces an existing class, you cannot use
54
+ `object.__init_subclass__` with *attrs* classes, because it runs too early.
55
+ As a replacement, you can define ``__attrs_init_subclass__`` on your class.
56
+ It will be called by *attrs* classes that subclass it after they're
57
+ created. See also :ref:`init-subclass`.
58
+
59
+ Args:
60
+ slots (bool):
61
+ Create a :term:`slotted class <slotted classes>` that's more
62
+ memory-efficient. Slotted classes are generally superior to the
63
+ default dict classes, but have some gotchas you should know about,
64
+ so we encourage you to read the :term:`glossary entry <slotted
65
+ classes>`.
66
+
67
+ auto_detect (bool):
68
+ Instead of setting the *init*, *repr*, *eq*, and *hash* arguments
69
+ explicitly, assume they are set to True **unless any** of the
70
+ involved methods for one of the arguments is implemented in the
71
+ *current* class (meaning, it is *not* inherited from some base
72
+ class).
73
+
74
+ So, for example by implementing ``__eq__`` on a class yourself,
75
+ *attrs* will deduce ``eq=False`` and will create *neither*
76
+ ``__eq__`` *nor* ``__ne__`` (but Python classes come with a
77
+ sensible ``__ne__`` by default, so it *should* be enough to only
78
+ implement ``__eq__`` in most cases).
79
+
80
+ Passing True or False` to *init*, *repr*, *eq*, *cmp*, or *hash*
81
+ overrides whatever *auto_detect* would determine.
82
+
83
+ auto_exc (bool):
84
+ If the class subclasses `BaseException` (which implicitly includes
85
+ any subclass of any exception), the following happens to behave
86
+ like a well-behaved Python exception class:
87
+
88
+ - the values for *eq*, *order*, and *hash* are ignored and the
89
+ instances compare and hash by the instance's ids [#]_ ,
90
+ - all attributes that are either passed into ``__init__`` or have a
91
+ default value are additionally available as a tuple in the
92
+ ``args`` attribute,
93
+ - the value of *str* is ignored leaving ``__str__`` to base
94
+ classes.
95
+
96
+ .. [#]
97
+ Note that *attrs* will *not* remove existing implementations of
98
+ ``__hash__`` or the equality methods. It just won't add own
99
+ ones.
100
+
101
+ on_setattr (~typing.Callable | list[~typing.Callable] | None | ~typing.Literal[attrs.setters.NO_OP]):
102
+ A callable that is run whenever the user attempts to set an
103
+ attribute (either by assignment like ``i.x = 42`` or by using
104
+ `setattr` like ``setattr(i, "x", 42)``). It receives the same
105
+ arguments as validators: the instance, the attribute that is being
106
+ modified, and the new value.
107
+
108
+ If no exception is raised, the attribute is set to the return value
109
+ of the callable.
110
+
111
+ If a list of callables is passed, they're automatically wrapped in
112
+ an `attrs.setters.pipe`.
113
+
114
+ If left None, the default behavior is to run converters and
115
+ validators whenever an attribute is set.
116
+
117
+ init (bool):
118
+ Create a ``__init__`` method that initializes the *attrs*
119
+ attributes. Leading underscores are stripped for the argument name,
120
+ unless an alias is set on the attribute.
121
+
122
+ .. seealso::
123
+ `init` shows advanced ways to customize the generated
124
+ ``__init__`` method, including executing code before and after.
125
+
126
+ repr(bool):
127
+ Create a ``__repr__`` method with a human readable representation
128
+ of *attrs* attributes.
129
+
130
+ str (bool):
131
+ Create a ``__str__`` method that is identical to ``__repr__``. This
132
+ is usually not necessary except for `Exception`\ s.
133
+
134
+ eq (bool | None):
135
+ If True or None (default), add ``__eq__`` and ``__ne__`` methods
136
+ that check two instances for equality.
137
+
138
+ .. seealso::
139
+ `comparison` describes how to customize the comparison behavior
140
+ going as far comparing NumPy arrays.
141
+
142
+ order (bool | None):
143
+ If True, add ``__lt__``, ``__le__``, ``__gt__``, and ``__ge__``
144
+ methods that behave like *eq* above and allow instances to be
145
+ ordered.
146
+
147
+ They compare the instances as if they were tuples of their *attrs*
148
+ attributes if and only if the types of both classes are
149
+ *identical*.
150
+
151
+ If `None` mirror value of *eq*.
152
+
153
+ .. seealso:: `comparison`
154
+
155
+ cmp (bool | None):
156
+ Setting *cmp* is equivalent to setting *eq* and *order* to the same
157
+ value. Must not be mixed with *eq* or *order*.
158
+
159
+ unsafe_hash (bool | None):
160
+ If None (default), the ``__hash__`` method is generated according
161
+ how *eq* and *frozen* are set.
162
+
163
+ 1. If *both* are True, *attrs* will generate a ``__hash__`` for
164
+ you.
165
+ 2. If *eq* is True and *frozen* is False, ``__hash__`` will be set
166
+ to None, marking it unhashable (which it is).
167
+ 3. If *eq* is False, ``__hash__`` will be left untouched meaning
168
+ the ``__hash__`` method of the base class will be used. If the
169
+ base class is `object`, this means it will fall back to id-based
170
+ hashing.
171
+
172
+ Although not recommended, you can decide for yourself and force
173
+ *attrs* to create one (for example, if the class is immutable even
174
+ though you didn't freeze it programmatically) by passing True or
175
+ not. Both of these cases are rather special and should be used
176
+ carefully.
177
+
178
+ .. seealso::
179
+
180
+ - Our documentation on `hashing`,
181
+ - Python's documentation on `object.__hash__`,
182
+ - and the `GitHub issue that led to the default \ behavior
183
+ <https://github.com/python-attrs/attrs/issues/136>`_ for more
184
+ details.
185
+
186
+ hash (bool | None):
187
+ Deprecated alias for *unsafe_hash*. *unsafe_hash* takes precedence.
188
+
189
+ cache_hash (bool):
190
+ Ensure that the object's hash code is computed only once and stored
191
+ on the object. If this is set to True, hashing must be either
192
+ explicitly or implicitly enabled for this class. If the hash code
193
+ is cached, avoid any reassignments of fields involved in hash code
194
+ computation or mutations of the objects those fields point to after
195
+ object creation. If such changes occur, the behavior of the
196
+ object's hash code is undefined.
197
+
198
+ frozen (bool):
199
+ Make instances immutable after initialization. If someone attempts
200
+ to modify a frozen instance, `attrs.exceptions.FrozenInstanceError`
201
+ is raised.
202
+
203
+ .. note::
204
+
205
+ 1. This is achieved by installing a custom ``__setattr__``
206
+ method on your class, so you can't implement your own.
207
+
208
+ 2. True immutability is impossible in Python.
209
+
210
+ 3. This *does* have a minor a runtime performance `impact
211
+ <how-frozen>` when initializing new instances. In other
212
+ words: ``__init__`` is slightly slower with ``frozen=True``.
213
+
214
+ 4. If a class is frozen, you cannot modify ``self`` in
215
+ ``__attrs_post_init__`` or a self-written ``__init__``. You
216
+ can circumvent that limitation by using
217
+ ``object.__setattr__(self, "attribute_name", value)``.
218
+
219
+ 5. Subclasses of a frozen class are frozen too.
220
+
221
+ kw_only (bool):
222
+ Make all attributes keyword-only in the generated ``__init__`` (if
223
+ *init* is False, this parameter is ignored).
224
+
225
+ weakref_slot (bool):
226
+ Make instances weak-referenceable. This has no effect unless
227
+ *slots* is True.
228
+
229
+ field_transformer (~typing.Callable | None):
230
+ A function that is called with the original class object and all
231
+ fields right before *attrs* finalizes the class. You can use this,
232
+ for example, to automatically add converters or validators to
233
+ fields based on their types.
234
+
235
+ .. seealso:: `transform-fields`
236
+
237
+ match_args (bool):
238
+ If True (default), set ``__match_args__`` on the class to support
239
+ :pep:`634` (*Structural Pattern Matching*). It is a tuple of all
240
+ non-keyword-only ``__init__`` parameter names on Python 3.10 and
241
+ later. Ignored on older Python versions.
242
+
243
+ collect_by_mro (bool):
244
+ If True, *attrs* collects attributes from base classes correctly
245
+ according to the `method resolution order
246
+ <https://docs.python.org/3/howto/mro.html>`_. If False, *attrs*
247
+ will mimic the (wrong) behavior of `dataclasses` and :pep:`681`.
248
+
249
+ See also `issue #428
250
+ <https://github.com/python-attrs/attrs/issues/428>`_.
251
+
252
+ getstate_setstate (bool | None):
253
+ .. note::
254
+
255
+ This is usually only interesting for slotted classes and you
256
+ should probably just set *auto_detect* to True.
257
+
258
+ If True, ``__getstate__`` and ``__setstate__`` are generated and
259
+ attached to the class. This is necessary for slotted classes to be
260
+ pickleable. If left None, it's True by default for slotted classes
261
+ and False for dict classes.
262
+
263
+ If *auto_detect* is True, and *getstate_setstate* is left None, and
264
+ **either** ``__getstate__`` or ``__setstate__`` is detected
265
+ directly on the class (meaning: not inherited), it is set to False
266
+ (this is usually what you want).
267
+
268
+ auto_attribs (bool | None):
269
+ If True, look at type annotations to determine which attributes to
270
+ use, like `dataclasses`. If False, it will only look for explicit
271
+ :func:`field` class attributes, like classic *attrs*.
272
+
273
+ If left None, it will guess:
274
+
275
+ 1. If any attributes are annotated and no unannotated
276
+ `attrs.field`\ s are found, it assumes *auto_attribs=True*.
277
+ 2. Otherwise it assumes *auto_attribs=False* and tries to collect
278
+ `attrs.field`\ s.
279
+
280
+ If *attrs* decides to look at type annotations, **all** fields
281
+ **must** be annotated. If *attrs* encounters a field that is set to
282
+ a :func:`field` / `attr.ib` but lacks a type annotation, an
283
+ `attrs.exceptions.UnannotatedAttributeError` is raised. Use
284
+ ``field_name: typing.Any = field(...)`` if you don't want to set a
285
+ type.
286
+
287
+ .. warning::
288
+
289
+ For features that use the attribute name to create decorators
290
+ (for example, :ref:`validators <validators>`), you still *must*
291
+ assign :func:`field` / `attr.ib` to them. Otherwise Python will
292
+ either not find the name or try to use the default value to
293
+ call, for example, ``validator`` on it.
294
+
295
+ Attributes annotated as `typing.ClassVar`, and attributes that are
296
+ neither annotated nor set to an `field()` are **ignored**.
297
+
298
+ these (dict[str, object]):
299
+ A dictionary of name to the (private) return value of `field()`
300
+ mappings. This is useful to avoid the definition of your attributes
301
+ within the class body because you can't (for example, if you want
302
+ to add ``__repr__`` methods to Django models) or don't want to.
303
+
304
+ If *these* is not `None`, *attrs* will *not* search the class body
305
+ for attributes and will *not* remove any attributes from it.
306
+
307
+ The order is deduced from the order of the attributes inside
308
+ *these*.
309
+
310
+ Arguably, this is a rather obscure feature.
311
+
312
+ .. versionadded:: 20.1.0
313
+ .. versionchanged:: 21.3.0 Converters are also run ``on_setattr``.
314
+ .. versionadded:: 22.2.0
315
+ *unsafe_hash* as an alias for *hash* (for :pep:`681` compliance).
316
+ .. versionchanged:: 24.1.0
317
+ Instances are not compared as tuples of attributes anymore, but using a
318
+ big ``and`` condition. This is faster and has more correct behavior for
319
+ uncomparable values like `math.nan`.
320
+ .. versionadded:: 24.1.0
321
+ If a class has an *inherited* classmethod called
322
+ ``__attrs_init_subclass__``, it is executed after the class is created.
323
+ .. deprecated:: 24.1.0 *hash* is deprecated in favor of *unsafe_hash*.
324
+
325
+ .. note::
326
+
327
+ The main differences to the classic `attr.s` are:
328
+
329
+ - Automatically detect whether or not *auto_attribs* should be `True`
330
+ (c.f. *auto_attribs* parameter).
331
+ - Converters and validators run when attributes are set by default --
332
+ if *frozen* is `False`.
333
+ - *slots=True*
334
+
335
+ Usually, this has only upsides and few visible effects in everyday
336
+ programming. But it *can* lead to some surprising behaviors, so
337
+ please make sure to read :term:`slotted classes`.
338
+
339
+ - *auto_exc=True*
340
+ - *auto_detect=True*
341
+ - *order=False*
342
+ - Some options that were only relevant on Python 2 or were kept around
343
+ for backwards-compatibility have been removed.
344
+
345
+ """
346
+
347
+ def do_it(cls, auto_attribs):
348
+ return attrs(
349
+ maybe_cls=cls,
350
+ these=these,
351
+ repr=repr,
352
+ hash=hash,
353
+ unsafe_hash=unsafe_hash,
354
+ init=init,
355
+ slots=slots,
356
+ frozen=frozen,
357
+ weakref_slot=weakref_slot,
358
+ str=str,
359
+ auto_attribs=auto_attribs,
360
+ kw_only=kw_only,
361
+ cache_hash=cache_hash,
362
+ auto_exc=auto_exc,
363
+ eq=eq,
364
+ order=order,
365
+ auto_detect=auto_detect,
366
+ collect_by_mro=True,
367
+ getstate_setstate=getstate_setstate,
368
+ on_setattr=on_setattr,
369
+ field_transformer=field_transformer,
370
+ match_args=match_args,
371
+ )
372
+
373
+ def wrap(cls):
374
+ """
375
+ Making this a wrapper ensures this code runs during class creation.
376
+
377
+ We also ensure that frozen-ness of classes is inherited.
378
+ """
379
+ nonlocal frozen, on_setattr
380
+
381
+ had_on_setattr = on_setattr not in (None, setters.NO_OP)
382
+
383
+ # By default, mutable classes convert & validate on setattr.
384
+ if frozen is False and on_setattr is None:
385
+ on_setattr = _DEFAULT_ON_SETATTR
386
+
387
+ # However, if we subclass a frozen class, we inherit the immutability
388
+ # and disable on_setattr.
389
+ for base_cls in cls.__bases__:
390
+ if base_cls.__setattr__ is _frozen_setattrs:
391
+ if had_on_setattr:
392
+ msg = "Frozen classes can't use on_setattr (frozen-ness was inherited)."
393
+ raise ValueError(msg)
394
+
395
+ on_setattr = setters.NO_OP
396
+ break
397
+
398
+ if auto_attribs is not None:
399
+ return do_it(cls, auto_attribs)
400
+
401
+ try:
402
+ return do_it(cls, True)
403
+ except UnannotatedAttributeError:
404
+ return do_it(cls, False)
405
+
406
+ # maybe_cls's type depends on the usage of the decorator. It's a class
407
+ # if it's used as `@attrs` but `None` if used as `@attrs()`.
408
+ if maybe_cls is None:
409
+ return wrap
410
+
411
+ return wrap(maybe_cls)
412
+
413
+
414
+ mutable = define
415
+ frozen = partial(define, frozen=True, on_setattr=None)
416
+
417
+
418
+ def field(
419
+ *,
420
+ default=NOTHING,
421
+ validator=None,
422
+ repr=True,
423
+ hash=None,
424
+ init=True,
425
+ metadata=None,
426
+ type=None,
427
+ converter=None,
428
+ factory=None,
429
+ kw_only=False,
430
+ eq=None,
431
+ order=None,
432
+ on_setattr=None,
433
+ alias=None,
434
+ ):
435
+ """
436
+ Create a new :term:`field` / :term:`attribute` on a class.
437
+
438
+ .. warning::
439
+
440
+ Does **nothing** unless the class is also decorated with
441
+ `attrs.define` (or similar)!
442
+
443
+ Args:
444
+ default:
445
+ A value that is used if an *attrs*-generated ``__init__`` is used
446
+ and no value is passed while instantiating or the attribute is
447
+ excluded using ``init=False``.
448
+
449
+ If the value is an instance of `attrs.Factory`, its callable will
450
+ be used to construct a new value (useful for mutable data types
451
+ like lists or dicts).
452
+
453
+ If a default is not set (or set manually to `attrs.NOTHING`), a
454
+ value *must* be supplied when instantiating; otherwise a
455
+ `TypeError` will be raised.
456
+
457
+ .. seealso:: `defaults`
458
+
459
+ factory (~typing.Callable):
460
+ Syntactic sugar for ``default=attr.Factory(factory)``.
461
+
462
+ validator (~typing.Callable | list[~typing.Callable]):
463
+ Callable that is called by *attrs*-generated ``__init__`` methods
464
+ after the instance has been initialized. They receive the
465
+ initialized instance, the :func:`~attrs.Attribute`, and the passed
466
+ value.
467
+
468
+ The return value is *not* inspected so the validator has to throw
469
+ an exception itself.
470
+
471
+ If a `list` is passed, its items are treated as validators and must
472
+ all pass.
473
+
474
+ Validators can be globally disabled and re-enabled using
475
+ `attrs.validators.get_disabled` / `attrs.validators.set_disabled`.
476
+
477
+ The validator can also be set using decorator notation as shown
478
+ below.
479
+
480
+ .. seealso:: :ref:`validators`
481
+
482
+ repr (bool | ~typing.Callable):
483
+ Include this attribute in the generated ``__repr__`` method. If
484
+ True, include the attribute; if False, omit it. By default, the
485
+ built-in ``repr()`` function is used. To override how the attribute
486
+ value is formatted, pass a ``callable`` that takes a single value
487
+ and returns a string. Note that the resulting string is used as-is,
488
+ which means it will be used directly *instead* of calling
489
+ ``repr()`` (the default).
490
+
491
+ eq (bool | ~typing.Callable):
492
+ If True (default), include this attribute in the generated
493
+ ``__eq__`` and ``__ne__`` methods that check two instances for
494
+ equality. To override how the attribute value is compared, pass a
495
+ callable that takes a single value and returns the value to be
496
+ compared.
497
+
498
+ .. seealso:: `comparison`
499
+
500
+ order (bool | ~typing.Callable):
501
+ If True (default), include this attributes in the generated
502
+ ``__lt__``, ``__le__``, ``__gt__`` and ``__ge__`` methods. To
503
+ override how the attribute value is ordered, pass a callable that
504
+ takes a single value and returns the value to be ordered.
505
+
506
+ .. seealso:: `comparison`
507
+
508
+ cmp(bool | ~typing.Callable):
509
+ Setting *cmp* is equivalent to setting *eq* and *order* to the same
510
+ value. Must not be mixed with *eq* or *order*.
511
+
512
+ .. seealso:: `comparison`
513
+
514
+ hash (bool | None):
515
+ Include this attribute in the generated ``__hash__`` method. If
516
+ None (default), mirror *eq*'s value. This is the correct behavior
517
+ according the Python spec. Setting this value to anything else
518
+ than None is *discouraged*.
519
+
520
+ .. seealso:: `hashing`
521
+
522
+ init (bool):
523
+ Include this attribute in the generated ``__init__`` method.
524
+
525
+ It is possible to set this to False and set a default value. In
526
+ that case this attributed is unconditionally initialized with the
527
+ specified default value or factory.
528
+
529
+ .. seealso:: `init`
530
+
531
+ converter (typing.Callable | Converter):
532
+ A callable that is called by *attrs*-generated ``__init__`` methods
533
+ to convert attribute's value to the desired format.
534
+
535
+ If a vanilla callable is passed, it is given the passed-in value as
536
+ the only positional argument. It is possible to receive additional
537
+ arguments by wrapping the callable in a `Converter`.
538
+
539
+ Either way, the returned value will be used as the new value of the
540
+ attribute. The value is converted before being passed to the
541
+ validator, if any.
542
+
543
+ .. seealso:: :ref:`converters`
544
+
545
+ metadata (dict | None):
546
+ An arbitrary mapping, to be used by third-party code.
547
+
548
+ .. seealso:: `extending-metadata`.
549
+
550
+ type (type):
551
+ The type of the attribute. Nowadays, the preferred method to
552
+ specify the type is using a variable annotation (see :pep:`526`).
553
+ This argument is provided for backwards-compatibility and for usage
554
+ with `make_class`. Regardless of the approach used, the type will
555
+ be stored on ``Attribute.type``.
556
+
557
+ Please note that *attrs* doesn't do anything with this metadata by
558
+ itself. You can use it as part of your own code or for `static type
559
+ checking <types>`.
560
+
561
+ kw_only (bool):
562
+ Make this attribute keyword-only in the generated ``__init__`` (if
563
+ ``init`` is False, this parameter is ignored).
564
+
565
+ on_setattr (~typing.Callable | list[~typing.Callable] | None | ~typing.Literal[attrs.setters.NO_OP]):
566
+ Allows to overwrite the *on_setattr* setting from `attr.s`. If left
567
+ None, the *on_setattr* value from `attr.s` is used. Set to
568
+ `attrs.setters.NO_OP` to run **no** `setattr` hooks for this
569
+ attribute -- regardless of the setting in `define()`.
570
+
571
+ alias (str | None):
572
+ Override this attribute's parameter name in the generated
573
+ ``__init__`` method. If left None, default to ``name`` stripped
574
+ of leading underscores. See `private-attributes`.
575
+
576
+ .. versionadded:: 20.1.0
577
+ .. versionchanged:: 21.1.0
578
+ *eq*, *order*, and *cmp* also accept a custom callable
579
+ .. versionadded:: 22.2.0 *alias*
580
+ .. versionadded:: 23.1.0
581
+ The *type* parameter has been re-added; mostly for `attrs.make_class`.
582
+ Please note that type checkers ignore this metadata.
583
+
584
+ .. seealso::
585
+
586
+ `attr.ib`
587
+ """
588
+ return attrib(
589
+ default=default,
590
+ validator=validator,
591
+ repr=repr,
592
+ hash=hash,
593
+ init=init,
594
+ metadata=metadata,
595
+ type=type,
596
+ converter=converter,
597
+ factory=factory,
598
+ kw_only=kw_only,
599
+ eq=eq,
600
+ order=order,
601
+ on_setattr=on_setattr,
602
+ alias=alias,
603
+ )
604
+
605
+
606
+ def asdict(inst, *, recurse=True, filter=None, value_serializer=None):
607
+ """
608
+ Same as `attr.asdict`, except that collections types are always retained
609
+ and dict is always used as *dict_factory*.
610
+
611
+ .. versionadded:: 21.3.0
612
+ """
613
+ return _asdict(
614
+ inst=inst,
615
+ recurse=recurse,
616
+ filter=filter,
617
+ value_serializer=value_serializer,
618
+ retain_collection_types=True,
619
+ )
620
+
621
+
622
+ def astuple(inst, *, recurse=True, filter=None):
623
+ """
624
+ Same as `attr.astuple`, except that collections types are always retained
625
+ and `tuple` is always used as the *tuple_factory*.
626
+
627
+ .. versionadded:: 21.3.0
628
+ """
629
+ return _astuple(
630
+ inst=inst, recurse=recurse, filter=filter, retain_collection_types=True
631
+ )
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/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
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/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
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/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: ...
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/converters.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 has
28
+ any.
29
+
30
+ Args:
31
+ converter (typing.Callable):
32
+ the converter that is used for non-`None` values.
33
+
34
+ .. versionadded:: 17.1.0
35
+ """
36
+
37
+ def optional_converter(val):
38
+ if val is None:
39
+ return None
40
+ return converter(val)
41
+
42
+ xtr = _AnnotationExtractor(converter)
43
+
44
+ t = xtr.get_first_param_type()
45
+ if t:
46
+ optional_converter.__annotations__["val"] = typing.Optional[t]
47
+
48
+ rt = xtr.get_return_type()
49
+ if rt:
50
+ optional_converter.__annotations__["return"] = typing.Optional[rt]
51
+
52
+ return optional_converter
53
+
54
+
55
+ def default_if_none(default=NOTHING, factory=None):
56
+ """
57
+ A converter that allows to replace `None` values by *default* or the result
58
+ of *factory*.
59
+
60
+ Args:
61
+ default:
62
+ Value to be used if `None` is passed. Passing an instance of
63
+ `attrs.Factory` is supported, however the ``takes_self`` option is
64
+ *not*.
65
+
66
+ factory (typing.Callable):
67
+ A callable that takes no parameters whose result is used if `None`
68
+ is passed.
69
+
70
+ Raises:
71
+ TypeError: If **neither** *default* or *factory* is passed.
72
+
73
+ TypeError: If **both** *default* and *factory* are passed.
74
+
75
+ ValueError:
76
+ If an instance of `attrs.Factory` is passed with
77
+ ``takes_self=True``.
78
+
79
+ .. versionadded:: 18.2.0
80
+ """
81
+ if default is NOTHING and factory is None:
82
+ msg = "Must pass either `default` or `factory`."
83
+ raise TypeError(msg)
84
+
85
+ if default is not NOTHING and factory is not None:
86
+ msg = "Must pass either `default` or `factory` but not both."
87
+ raise TypeError(msg)
88
+
89
+ if factory is not None:
90
+ default = Factory(factory)
91
+
92
+ if isinstance(default, Factory):
93
+ if default.takes_self:
94
+ msg = "`takes_self` is not supported by default_if_none."
95
+ raise ValueError(msg)
96
+
97
+ def default_if_none_converter(val):
98
+ if val is not None:
99
+ return val
100
+
101
+ return default.factory()
102
+
103
+ else:
104
+
105
+ def default_if_none_converter(val):
106
+ if val is not None:
107
+ return val
108
+
109
+ return default
110
+
111
+ return default_if_none_converter
112
+
113
+
114
+ def to_bool(val):
115
+ """
116
+ Convert "boolean" strings (for example, from environment variables) to real
117
+ booleans.
118
+
119
+ Values mapping to `True`:
120
+
121
+ - ``True``
122
+ - ``"true"`` / ``"t"``
123
+ - ``"yes"`` / ``"y"``
124
+ - ``"on"``
125
+ - ``"1"``
126
+ - ``1``
127
+
128
+ Values mapping to `False`:
129
+
130
+ - ``False``
131
+ - ``"false"`` / ``"f"``
132
+ - ``"no"`` / ``"n"``
133
+ - ``"off"``
134
+ - ``"0"``
135
+ - ``0``
136
+
137
+ Raises:
138
+ ValueError: For any other value.
139
+
140
+ .. versionadded:: 21.3.0
141
+ """
142
+ if isinstance(val, str):
143
+ val = val.lower()
144
+
145
+ if val in (True, "true", "t", "yes", "y", "on", "1", 1):
146
+ return True
147
+ if val in (False, "false", "f", "no", "n", "off", "0", 0):
148
+ return False
149
+
150
+ msg = f"Cannot convert value to bool: {val!r}"
151
+ raise ValueError(msg)
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/converters.pyi ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Callable, TypeVar, overload
2
+
3
+ from attrs 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: ...
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/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)
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/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: ...
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/filters.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: MIT
2
+
3
+ """
4
+ Commonly useful filters for `attrs.asdict` and `attrs.astuple`.
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
+ Create a filter that only allows *what*.
24
+
25
+ Args:
26
+ what (list[type, str, attrs.Attribute]):
27
+ What to include. Can be a type, a name, or an attribute.
28
+
29
+ Returns:
30
+ Callable:
31
+ A callable that can be passed to `attrs.asdict`'s and
32
+ `attrs.astuple`'s *filter* argument.
33
+
34
+ .. versionchanged:: 23.1.0 Accept strings with field names.
35
+ """
36
+ cls, names, attrs = _split_what(what)
37
+
38
+ def include_(attribute, value):
39
+ return (
40
+ value.__class__ in cls
41
+ or attribute.name in names
42
+ or attribute in attrs
43
+ )
44
+
45
+ return include_
46
+
47
+
48
+ def exclude(*what):
49
+ """
50
+ Create a filter that does **not** allow *what*.
51
+
52
+ Args:
53
+ what (list[type, str, attrs.Attribute]):
54
+ What to exclude. Can be a type, a name, or an attribute.
55
+
56
+ Returns:
57
+ Callable:
58
+ A callable that can be passed to `attrs.asdict`'s and
59
+ `attrs.astuple`'s *filter* argument.
60
+
61
+ .. versionchanged:: 23.3.0 Accept field name string as input argument
62
+ """
63
+ cls, names, attrs = _split_what(what)
64
+
65
+ def exclude_(attribute, value):
66
+ return not (
67
+ value.__class__ in cls
68
+ or attribute.name in names
69
+ or attribute in attrs
70
+ )
71
+
72
+ return exclude_
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/filters.pyi ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from typing import Any
2
+
3
+ from . import Attribute, _FilterType
4
+
5
+ def include(*what: type | str | Attribute[Any]) -> _FilterType[Any]: ...
6
+ def exclude(*what: type | str | Attribute[Any]) -> _FilterType[Any]: ...
vllm/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/attr/py.typed ADDED
File without changes