Skip to content

Commit 8499299

Browse files
committed
Tickle the type checker to make more silly type:ignores go away.
1 parent 337e470 commit 8499299

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

referencing/_core.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
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
55
from urllib.parse import unquote, urldefrag, urljoin
66

77
from attrs import evolve, field
@@ -12,7 +12,9 @@
1212
from referencing._attrs import frozen
1313
from referencing.typing import URI, Anchor as AnchorType, D, Mapping
1414

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)
1618

1719

1820
class _MaybeInSubresource(Protocol[D]):
@@ -234,11 +236,13 @@ class Registry(Mapping[URI, Resource[D]]):
234236
"""
235237

236238
_resources: PMap[URI, Resource[D]] = field(
237-
default=EMPTY64, # type: ignore[reportUnknownArgumentType]
239+
default=EMPTY_RESOURCES,
238240
converter=_to_pmap,
239241
)
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)
242246
_retrieve: Callable[[URI], Resource[D]] = field(default=_fail_to_retrieve)
243247

244248
def __getitem__(self, uri: URI) -> Resource[D]:
@@ -332,7 +336,7 @@ def crawl(self) -> Registry[D]:
332336
self,
333337
resources=resources.persistent(),
334338
anchors=anchors.persistent(),
335-
uncrawled=pset(),
339+
uncrawled=EMPTY_UNCRAWLED,
336340
)
337341

338342
def with_resource(self, uri: URI, resource: Resource[D]):

0 commit comments

Comments
 (0)