23andMe / Yamale

A schema and validator for YAML.
MIT License
666 stars 88 forks source link

Question regarding the "tag" property and linting #221

Open nbaju1 opened 1 year ago

nbaju1 commented 1 year ago

This is more of a general Python question than specific to Yamale, I guess.

PyLance complains about how Yamale implements the tag attribute on validators.

class SomeValidator(Validator):
    tag = "some_validator"

    def _is_valid(self, value):
        if value:
            return True
        return False

    def fail(self, value):
        return f"Value '{value}' is not valid."

Expression of type "Literal['some_validator']" cannot be assigned to declared type "property" "Literal['some_validator']" is incompatible with "property"

The validator works of course, as this is how the tags are implemented by default.

Is there a reason as to why tag was implemented as a property instead of as a class attribute (which PyLance does not complain about)? E.g

class Validator(object):
    """Base class for all Validators"""
    constraints = []
    value_type = None

    def __init__(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs
        self.tag = self.__class__
...