22Retrieve JSON schemas for validating dicts representing a ``pyproject.toml`` file.
33"""
44
5+ from __future__ import annotations
6+
57import json
68import logging
79import sys
1113from types import MappingProxyType , ModuleType
1214from typing import (
1315 Callable ,
14- Dict ,
1516 Iterator ,
1617 Mapping ,
17- Optional ,
1818 Sequence ,
19- Tuple ,
2019 TypeVar ,
21- Union ,
2220)
2321
2422import fastjsonschema as FJS
3735if sys .version_info >= (3 , 9 ): # pragma: no cover
3836 from importlib .resources import files
3937
40- def read_text (package : Union [ str , ModuleType ] , resource : str ) -> str :
38+ def read_text (package : str | ModuleType , resource : str ) -> str :
4139 """:meta private:"""
4240 return files (package ).joinpath (resource ).read_text (encoding = "utf-8" )
4341
@@ -94,8 +92,8 @@ class SchemaRegistry(Mapping[str, Schema]):
9492 :meta private: (low level detail)
9593 """
9694
97- def __init__ (self , plugins : Sequence [" PluginProtocol" ] = ()):
98- self ._schemas : Dict [str , Tuple [str , str , Schema ]] = {}
95+ def __init__ (self , plugins : Sequence [PluginProtocol ] = ()):
96+ self ._schemas : dict [str , tuple [str , str , Schema ]] = {}
9997 # (which part of the TOML, who defines, schema)
10098
10199 top_level = typing .cast ("dict" , load (TOP_LEVEL_SCHEMA )) # Make it mutable
@@ -114,7 +112,7 @@ def __init__(self, plugins: Sequence["PluginProtocol"] = ()):
114112 # Add tools using Plugins
115113 for plugin in plugins :
116114 if plugin .tool :
117- allow_overwrite : Optional [ str ] = None
115+ allow_overwrite : str | None = None
118116 if plugin .tool in tool_properties :
119117 _logger .warning (f"{ plugin } overwrites `tool.{ plugin .tool } ` schema" )
120118 allow_overwrite = plugin .schema .get ("$id" )
@@ -150,7 +148,7 @@ def _ensure_compatibility(
150148 self ,
151149 reference : str ,
152150 schema : Schema ,
153- allow_overwrite : Optional [ str ] = None ,
151+ allow_overwrite : str | None = None ,
154152 ) -> Schema :
155153 if "$id" not in schema or not schema ["$id" ]:
156154 raise errors .SchemaMissingId (reference or "<extra>" )
@@ -208,19 +206,19 @@ def __getitem__(self, key: str) -> Callable[[str], Schema]:
208206
209207
210208class Validator :
211- _plugins : Sequence [" PluginProtocol" ]
209+ _plugins : Sequence [PluginProtocol ]
212210
213211 def __init__ (
214212 self ,
215- plugins : Union [ Sequence [" PluginProtocol" ], AllPlugins ] = ALL_PLUGINS ,
213+ plugins : Sequence [PluginProtocol ] | AllPlugins = ALL_PLUGINS ,
216214 format_validators : Mapping [str , FormatValidationFn ] = FORMAT_FUNCTIONS ,
217215 extra_validations : Sequence [ValidationFn ] = EXTRA_VALIDATIONS ,
218216 * ,
219- extra_plugins : Sequence [" PluginProtocol" ] = (),
217+ extra_plugins : Sequence [PluginProtocol ] = (),
220218 ):
221- self ._code_cache : Optional [ str ] = None
222- self ._cache : Optional [ ValidationFn ] = None
223- self ._schema : Optional [ Schema ] = None
219+ self ._code_cache : str | None = None
220+ self ._cache : ValidationFn | None = None
221+ self ._schema : Schema | None = None
224222
225223 # Let's make the following options readonly
226224 self ._format_validators = MappingProxyType (format_validators )
0 commit comments