summaryrefslogtreecommitdiff
path: root/jsonschema/validators.py
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2022-08-18 11:22:16 +0300
committerJulian Berman <Julian@GrayVines.com>2022-08-18 11:22:16 +0300
commite69cb7ab504740a58766fad757bb5d01e5e812f6 (patch)
tree361f6a90486e88d868cbf171709c10f2d2aacfed /jsonschema/validators.py
parent549f9e545aae5ab6812940e082795527557e1448 (diff)
downloadjsonschema-e69cb7ab504740a58766fad757bb5d01e5e812f6.tar.gz
Warn at runtime when subclassing validator classes.v4.12.0
Doing so was not intended to be public API, though it seems some downstream libraries do so. A future version will make this an error, as it is brittle and better served by composing validator objects instead. Feel free to reach out if there are any cases where changing existing code seems difficult and I can try to provide guidance. Refs: #982
Diffstat (limited to 'jsonschema/validators.py')
-rw-r--r--jsonschema/validators.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/jsonschema/validators.py b/jsonschema/validators.py
index 79a8da3..e6d5370 100644
--- a/jsonschema/validators.py
+++ b/jsonschema/validators.py
@@ -191,6 +191,21 @@ def create(
resolver = attr.ib(default=None, repr=False)
format_checker = attr.ib(default=None)
+ def __init_subclass__(cls):
+ warnings.warn(
+ (
+ "Subclassing validator classes is not intended to "
+ "be part of their public API. A future version "
+ "will make doing so an error, as the behavior of "
+ "subclasses isn't guaranteed to stay the same "
+ "between releases of jsonschema. Instead, prefer "
+ "composition of validators, wrapping them in an object "
+ "owned entirely by the downstream library."
+ ),
+ DeprecationWarning,
+ stacklevel=2,
+ )
+
def __attrs_post_init__(self):
if self.resolver is None:
self.resolver = RefResolver.from_schema(