pyright icon indicating copy to clipboard operation
pyright copied to clipboard

Pyright raises type error when supplying an attr field with both default and a validator

Open bavalpey opened this issue 8 months ago • 2 comments

Describe the bug Pyright incorrectly reports an error when supplying both a validator and a default to attrs.field This does not seem to be a bug with the attrs package, as using mypy reports no issues.

Code or Screenshots

import attrs
@attrs.define
class Foo:
    a: bool = attrs.field(default=False, validator=attrs.validators.instance_of(bool))

image

Interestingly, if the validator is surrounded with parenthesis (which should have no effect), pyright reports no error:

import attrs
@attrs.define
class Foo:
    a: bool = attrs.field(default=False, validator=(attrs.validators.instance_of(bool)))

VS Code extension or command-line command-line, version 1.1.367

bavalpey avatar Jun 12 '24 20:06 bavalpey