blob: 7adc3e0f1522002f9ec652fb5075077b729f1d0b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# from __future__ import annotations
import dataclasses
import types
from typing import Annotated
@dataclasses.dataclass(frozen=True)
class FuncValidator:
func: types.FunctionType
@dataclasses.dataclass(frozen=True)
class MaxLen:
max_length: int
whitelisted_words: list[str]
def validate(value: str) -> str:
return value
#: Type alias for a validated string.
ValidatedString = Annotated[str, FuncValidator(validate)]
def hello(name: Annotated[str, "attribute"]) -> None:
"""docstring"""
pass
class AnnotatedAttributes:
"""docstring"""
#: Docstring about the ``name`` attribute.
name: Annotated[str, "attribute"]
#: Docstring about the ``max_len`` attribute.
max_len: list[Annotated[str, MaxLen(10, ['word_one', 'word_two'])]]
#: Docstring about the ``validated`` attribute.
validated: ValidatedString
|