Skip to content

Question regarding the "tag" property and linting #221

Open
@nbaju1

Description

@nbaju1

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__
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions