|
22 | 22 | from .utils import is_pydantic_change_detect_annotation
|
23 | 23 |
|
24 | 24 | if TYPE_CHECKING: # pragma: no cover
|
| 25 | + from pydantic import PrivateAttr |
25 | 26 | from pydantic.typing import AbstractSetIntStr, MappingIntStrAny
|
26 | 27 | if PYDANTIC_V1:
|
27 | 28 | from pydantic.typing import DictStrAny, SetStr
|
@@ -53,9 +54,17 @@ class Something(ChangeDetectionMixin, pydantic.BaseModel):
|
53 | 54 | """
|
54 | 55 |
|
55 | 56 | if TYPE_CHECKING: # pragma: no cover
|
56 |
| - model_original: Dict[str, Any] |
57 |
| - model_self_changed_fields: Set[str] |
58 |
| - model_changed_markers: set[str] |
| 57 | + # Note: Private attributes normally need to start with "_", but this code here |
| 58 | + # will only be seen by type checkers. So this is never an issue. The |
| 59 | + # usage of ` = PrivateAttr(...)` is also just here to make those type |
| 60 | + # checkers happy. Otherwise, they might "require" you to pass those |
| 61 | + # parameters to `__init__`, which is just plainly wrong. The private |
| 62 | + # attributes ChangeDetectionMixin uses are defined as __slots__ and |
| 63 | + # thus just new attributes the class has - not something you need to pass |
| 64 | + # anywhere. |
| 65 | + model_original: Dict[str, Any] = PrivateAttr(...) |
| 66 | + model_self_changed_fields: Set[str] = PrivateAttr(...) |
| 67 | + model_changed_markers: set[str] = PrivateAttr(...) |
59 | 68 |
|
60 | 69 | __slots__ = ("model_original", "model_self_changed_fields", "model_changed_markers")
|
61 | 70 |
|
|
0 commit comments