Skip to content

Commit df81704

Browse files
committed
Make Anchor a protocol (too) in prep for moving DynamicAnchor.
1 parent 00b3185 commit df81704

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

noxfile.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def typing(session):
6767
"attrs",
6868
"mypy",
6969
"pyrsistent",
70-
"types-jsonschema",
7170
str(ROOT),
7271
)
7372
session.run("python", "-m", "mypy", str(REFERENCING))

referencing/_core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from pyrsistent import m, plist, s
88
from pyrsistent.typing import PList, PMap, PSet
99

10+
from referencing.typing import Anchor as AnchorType, Schema, Specification
11+
1012

1113
class UnsupportedSubclassing(Exception):
1214
@classmethod
@@ -24,8 +26,6 @@ class UnidentifiedResource(Exception):
2426

2527
if TYPE_CHECKING:
2628
from attrs import define, evolve, field, frozen
27-
28-
from referencing.typing import AnchorType, Schema, Specification
2929
else:
3030
from attrs import define as _define, evolve, field, frozen as _frozen
3131

@@ -56,7 +56,7 @@ class DynamicAnchor:
5656
name: str
5757
resource: Schema
5858

59-
def resolve(self, dynamic_scope, uri) -> tuple[Schema, str]:
59+
def resolve(self, dynamic_scope, uri):
6060
last = self.resource
6161
for resource, anchors in dynamic_scope:
6262
anchor = anchors.get(self.name)
@@ -124,7 +124,7 @@ def with_resources(self, pairs) -> Registry:
124124
uncrawled = uncrawled.add(uri)
125125
return evolve(self, contents=contents, uncrawled=uncrawled)
126126

127-
def with_anchor(self, anchor: Anchor | DynamicAnchor) -> Registry:
127+
def with_anchor(self, anchor: AnchorType) -> Registry:
128128
resource, anchors = self._contents[anchor.uri]
129129
new = resource, anchors.set(anchor.name, anchor)
130130
return evolve(self, contents=self._contents.set(anchor.uri, new))

referencing/typing.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,26 @@
77
except TypeError:
88
from typing import Mapping
99

10-
from referencing._core import Anchor, DynamicAnchor
1110

1211
ObjectSchema = Mapping[str, Any]
1312
Schema = Union[bool, ObjectSchema]
14-
AnchorType = Union[Anchor, DynamicAnchor]
13+
14+
15+
class Anchor(Protocol):
16+
@property
17+
def uri(self) -> str:
18+
...
19+
20+
@property
21+
def name(self) -> str:
22+
...
23+
24+
def resolve(
25+
self,
26+
dynamic_scope: Iterable[tuple[Schema, "Anchor"]],
27+
uri: str,
28+
) -> tuple[Schema, str]:
29+
pass
1530

1631

1732
class Specification(Protocol):

0 commit comments

Comments
 (0)