You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to ignore type checking for a specific class instance that represents a Link in our YAML Schema. Right now I'm creating a new type checker, but to make it work as expected I have to create it with the "original" types taken from the private instance attribute _type_checkers of the original type checker.
Is this the best way to override the is_type function of a TypeChecker? I didn't want to monkey patch the function in the original TypeChecker.
classLinkTypeChecker(jsonschema.TypeChecker): """ A Custom jsonschema TypeChecker that always returns True for our custom Link class. """defis_type(self, instance: Any, type: str) ->bool: ifisinstance(instance, YamlLink): log.trace(f"Ignoring type validation for {instance}") returnTruereturnsuper().is_type(instance, type) defextend_validator(validator: type[jsonschema.Validator]) ->type[jsonschema.Validator]: _old_types=validator.TYPE_CHECKER._type_checkersvalidator=jsonschema.validators.extend(validator, type_checker=LinkTypeChecker(_old_types)) returnvalidatorvalidator_cls=jsonschema.validators.validator_for(schema) # noinspection PyTypeCheckervalidator_cls=extend_validator(validator_cls) validator=validator_cls(schema, registry=SCHEMA_REGISTRY)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm trying to ignore type checking for a specific class instance that represents a Link in our YAML Schema. Right now I'm creating a new type checker, but to make it work as expected I have to create it with the "original" types taken from the private instance attribute
_type_checkersof the original type checker.Is this the best way to override the
is_typefunction of a TypeChecker? I didn't want to monkey patch the function in the original TypeChecker.Beta Was this translation helpful? Give feedback.
All reactions