11from __future__ import annotations
22
33from collections .abc import Iterable , Mapping , Sequence
4- from typing import Any
4+ from typing import TYPE_CHECKING , Any
55from urllib .parse import unquote , urldefrag , urljoin
66
77from pyrsistent import m
@@ -23,14 +23,17 @@ class UnidentifiedResource(Exception):
2323 pass
2424
2525
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 :
2929
30+ def define (cls ):
31+ cls .__init_subclass__ = UnsupportedSubclassing .complain
32+ return attrs .define (cls )
3033
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 )
3437
3538
3639Schema = bool | Mapping [str , Any ]
@@ -83,7 +86,8 @@ def added_to(self, registry: Registry):
8386class Registry :
8487
8588 _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)" ,
8791 )
8892
8993 def resource_at (self , uri ):
@@ -173,7 +177,8 @@ def with_root(self, root) -> Resolver:
173177 else :
174178 uri = urljoin (self ._base_uri , maybe_relative )
175179 registry = self ._registry .with_identified_resource (
176- uri = uri , resource = root ,
180+ uri = uri ,
181+ resource = root ,
177182 )
178183 return attrs .evolve (self , base_uri = uri , registry = registry )
179184
0 commit comments