Skip to content

Commit f08c399

Browse files
committed
Hah. Get mypy to not complain incorrectly about init args.
Copied from 'python/mypy#5406 (comment)' rather than following the rest of the hack there.
1 parent cb24f96 commit f08c399

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

referencing/_core.py

Lines changed: 14 additions & 9 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, Mapping, Sequence
4-
from typing import Any
4+
from typing import TYPE_CHECKING, Any
55
from urllib.parse import unquote, urldefrag, urljoin
66

77
from 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

3639
Schema = bool | Mapping[str, Any]
@@ -83,7 +86,8 @@ def added_to(self, registry: Registry):
8386
class 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

Comments
 (0)