-
-
Notifications
You must be signed in to change notification settings - Fork 419
Closed
Description
I'm trying to correctly type hint the validator callback function of a class declared via @define and I'm a bit confused. Given the following example simplified from the documentation:
from attrs import define
@define
class C:
x: int
@x.validator
def fits_byte(self, attribute, value):
if not 0 <= value < 256:
raise ValueError("value out of bounds")What's the correct annotation for fits_byte? At a glance, it looked to me like it should be:
from typing import TYPE_CHECKING
from attrs import define
if TYPE_CHECKING:
from attrs import Attribute
@define
class C:
x: int
@x.validator
def fits_byte(self, attribute: Attribute[int], value: int) -> None:
... # rest of the codeIs this correct?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels