|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from collections.abc import Iterable, Iterator, Sequence |
4 | | -from typing import Any, Callable, ClassVar, Generic, Protocol |
| 4 | +from typing import Any, Callable, ClassVar, Generic, Protocol, cast |
5 | 5 | from urllib.parse import unquote, urldefrag, urljoin |
6 | 6 |
|
7 | 7 | from attrs import evolve, field |
|
12 | 12 | from referencing._attrs import frozen |
13 | 13 | from referencing.typing import URI, Anchor as AnchorType, D, Mapping |
14 | 14 |
|
15 | | -EMPTY64 = pmap(pre_size=64) |
| 15 | +EMPTY_RESOURCES: PMap[URI, Resource[Any]] = pmap({}, pre_size=64) |
| 16 | +EMPTY_ANCHORS = cast(PMap[tuple[URI, str], AnchorType[Any]], EMPTY_RESOURCES) |
| 17 | +EMPTY_UNCRAWLED: PSet[URI] = pset(pre_size=128) |
16 | 18 |
|
17 | 19 |
|
18 | 20 | class _MaybeInSubresource(Protocol[D]): |
@@ -234,11 +236,13 @@ class Registry(Mapping[URI, Resource[D]]): |
234 | 236 | """ |
235 | 237 |
|
236 | 238 | _resources: PMap[URI, Resource[D]] = field( |
237 | | - default=EMPTY64, # type: ignore[reportUnknownArgumentType] |
| 239 | + default=EMPTY_RESOURCES, |
238 | 240 | converter=_to_pmap, |
239 | 241 | ) |
240 | | - _anchors: PMap[tuple[URI, str], AnchorType[D]] = field(default=EMPTY64) # type: ignore[reportUnknownArgumentType] # noqa: E501 |
241 | | - _uncrawled: PSet[URI] = field(default=pset()) # type: ignore[reportUnknownArgumentType] # noqa: E501 |
| 242 | + _anchors: PMap[tuple[URI, str], AnchorType[D]] = field( |
| 243 | + default=EMPTY_ANCHORS, |
| 244 | + ) |
| 245 | + _uncrawled: PSet[URI] = field(default=EMPTY_UNCRAWLED) |
242 | 246 | _retrieve: Callable[[URI], Resource[D]] = field(default=_fail_to_retrieve) |
243 | 247 |
|
244 | 248 | def __getitem__(self, uri: URI) -> Resource[D]: |
@@ -332,7 +336,7 @@ def crawl(self) -> Registry[D]: |
332 | 336 | self, |
333 | 337 | resources=resources.persistent(), |
334 | 338 | anchors=anchors.persistent(), |
335 | | - uncrawled=pset(), |
| 339 | + uncrawled=EMPTY_UNCRAWLED, |
336 | 340 | ) |
337 | 341 |
|
338 | 342 | def with_resource(self, uri: URI, resource: Resource[D]): |
|
0 commit comments