Skip to content

Commit 4f7e8bc

Browse files
committed
Do more silly things to pepper over type checking nonsense.
See python/typing#689 and PEP 661 which look related. But really I still want my plugin that lets me separate between public API types and private API types.
1 parent eeae1d5 commit 4f7e8bc

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

docs/api.rst

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ Plainly then, you may rely on their methods and attributes not changing in backw
3939
:members:
4040
:undoc-members:
4141

42+
.. class:: referencing._core._Unset
43+
44+
A sentinel object used internally to satisfy the type checker.
45+
46+
Neither accessing nor explicitly passing this object anywhere is public API, and it is only documented here at all to get Sphinx to not complain.
47+
4248

4349
Submodules
4450
----------

docs/changes.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
=========
44

5+
v0.31.1
6+
-------
7+
8+
* No user facing changes.
9+
510
v0.31.0
611
-------
712

referencing/_core.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from collections.abc import Iterable, Iterator, Sequence
4+
from enum import Enum
45
from typing import Any, Callable, ClassVar, Generic, Protocol, TypeVar
56
from urllib.parse import unquote, urldefrag, urljoin
67

@@ -15,6 +16,17 @@
1516
EMPTY_PREVIOUS_RESOLVERS: List[URI] = List()
1617

1718

19+
class _Unset(Enum):
20+
"""
21+
What sillyness...
22+
"""
23+
24+
SENTINEL = 1
25+
26+
27+
_UNSET = _Unset.SENTINEL
28+
29+
1830
class _MaybeInSubresource(Protocol[D]):
1931
def __call__(
2032
self,
@@ -101,7 +113,7 @@ class Resource(Generic[D]):
101113
def from_contents(
102114
cls,
103115
contents: D,
104-
default_specification: Specification[D] = None, # type: ignore[reportGeneralTypeIssues]
116+
default_specification: Specification[D] | _Unset = _UNSET,
105117
) -> Resource[D]:
106118
"""
107119
Attempt to discern which specification applies to the given contents.
@@ -125,7 +137,7 @@ def from_contents(
125137
default=default_specification,
126138
)
127139

128-
if specification is None: # type: ignore[reportUnnecessaryComparison]
140+
if specification is _UNSET:
129141
raise exceptions.CannotDetermineSpecification(contents)
130142
return cls(contents=contents, specification=specification) # type: ignore[reportUnknownArgumentType]
131143

referencing/jsonschema.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from referencing import Anchor, Registry, Resource, Specification, exceptions
1111
from referencing._attrs import frozen
12+
from referencing._core import _UNSET # type: ignore[reportPrivateUsage]
13+
from referencing._core import _Unset # type: ignore[reportPrivateUsage]
1214
from referencing._core import Resolved as _Resolved, Resolver as _Resolver
1315
from referencing.typing import URI, Anchor as AnchorType, Mapping
1416

@@ -559,7 +561,7 @@ def maybe_in_subresource(
559561

560562
def specification_with(
561563
dialect_id: URI,
562-
default: Specification[Any] = None, # type: ignore[reportGeneralTypeIssues]
564+
default: Specification[Any] | _Unset = _UNSET,
563565
) -> Specification[Any]:
564566
"""
565567
Retrieve the `Specification` with the given dialect identifier.
@@ -573,7 +575,7 @@ def specification_with(
573575
resource = _SPECIFICATIONS.get(dialect_id.rstrip("#"))
574576
if resource is not None:
575577
return resource.contents
576-
if default is None: # type: ignore[reportUnnecessaryComparison]
578+
if default is _UNSET:
577579
raise UnknownDialect(dialect_id)
578580
return default
579581

0 commit comments

Comments
 (0)