Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question regarding the "tag" property and linting #221

Open
nbaju1 opened this issue Apr 19, 2023 · 0 comments
Open

Question regarding the "tag" property and linting #221

nbaju1 opened this issue Apr 19, 2023 · 0 comments

Comments

@nbaju1
Copy link

nbaju1 commented Apr 19, 2023

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__
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant