Skip to content

Commit 44f7a4e

Browse files
bmaranvillegvwilson
authored andcommitted
allow overlaying args on derived classes
1 parent 58ab3e1 commit 44f7a4e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

plotly/validator_cache.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import json
55
import os.path as opath
66

7+
DERIVED_CLASSES = {
8+
"DataValidator": "data",
9+
"LayoutValidator": "layout",
10+
}
11+
712
class ValidatorCache(object):
813
_cache = {}
914
_json_cache = None
@@ -43,8 +48,23 @@ def get_validator(parent_path, prop_name):
4348
lookup_name = lookup_name or prop_name
4449
lookup = f"{parent_path}.{lookup_name}" if parent_path else lookup_name
4550
validator_item = ValidatorCache._json_cache.get(lookup)
51+
validator_classname = validator_item["superclass"]
52+
if validator_classname in DERIVED_CLASSES:
53+
# If the superclass is a derived class, we need to get the base class
54+
# and pass the derived class name as a parameter
55+
base_item = ValidatorCache._json_cache.get(
56+
DERIVED_CLASSES[validator_classname]
57+
)
58+
validator_args = base_item["params"]
59+
validator_args.update(validator_item["params"])
60+
validator_classname = base_item["superclass"]
61+
else:
62+
validator_args = validator_item["params"]
63+
64+
validator_class = getattr(basevalidators, validator_classname)
65+
4666
print("validator_item", key, validator_item)
47-
validator = generate_validator(validator_item["params"], validator_item["superclass"])
67+
validator = validator_class(**validator_args)
4868
ValidatorCache._cache[key] = validator
4969

5070
return ValidatorCache._cache[key]

0 commit comments

Comments
 (0)