79272530

Date: 2024-12-11 16:51:14
Score: 1
Natty:
Report link

For anyone coming here from a search turns out I can just do:

import attrs


@attrs.define
class C:
  val: int | str = attrs.field(validator=attrs.validators.instance_of((str, int)))

This may mypy doesn't complain and runtime behavior is unaffected

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: I like Bananas