1
1
from __future__ import annotations
2
2
3
3
from collections .abc import Iterable , Mapping , Sequence
4
- from typing import Any
4
+ from typing import TYPE_CHECKING , Any
5
5
from urllib .parse import unquote , urldefrag , urljoin
6
6
7
7
from pyrsistent import m
@@ -23,14 +23,17 @@ class UnidentifiedResource(Exception):
23
23
pass
24
24
25
25
26
- def define ( cls ) :
27
- cls . __init_subclass__ = UnsupportedSubclassing . complain
28
- return attrs . define ( cls )
26
+ if TYPE_CHECKING :
27
+ from attrs import define , frozen
28
+ else :
29
29
30
+ def define (cls ):
31
+ cls .__init_subclass__ = UnsupportedSubclassing .complain
32
+ return attrs .define (cls )
30
33
31
- def frozen (cls ):
32
- cls .__init_subclass__ = UnsupportedSubclassing .complain
33
- return attrs .frozen (cls )
34
+ def frozen (cls ):
35
+ cls .__init_subclass__ = UnsupportedSubclassing .complain
36
+ return attrs .frozen (cls )
34
37
35
38
36
39
Schema = bool | Mapping [str , Any ]
@@ -83,7 +86,8 @@ def added_to(self, registry: Registry):
83
86
class Registry :
84
87
85
88
_contents : PMap [str , tuple [Schema , PMap [str , Schema ]]] = attrs .field (
86
- default = m (), repr = lambda value : f"({ len (value )} entries)" ,
89
+ default = m (),
90
+ repr = lambda value : f"({ len (value )} entries)" ,
87
91
)
88
92
89
93
def resource_at (self , uri ):
@@ -173,7 +177,8 @@ def with_root(self, root) -> Resolver:
173
177
else :
174
178
uri = urljoin (self ._base_uri , maybe_relative )
175
179
registry = self ._registry .with_identified_resource (
176
- uri = uri , resource = root ,
180
+ uri = uri ,
181
+ resource = root ,
177
182
)
178
183
return attrs .evolve (self , base_uri = uri , registry = registry )
179
184
0 commit comments