Commit 997ac44
authored
RelatedManager, ManyRelatedManager classes are sometimes useful for type hinting.
But these classes don't exist as is at Django runtime, rather they are defined inside function bodies.
* When `TYPE_CHECKING`, we re-export django-stubs fake classes.
* At runtime, we define these as `Protocol[_T]`.
This has the advantage that Python prevents them being used with isinstance().
Usage before:
```python
if TYPE_CHECKING:
from django.db.models.manager import RelatedManager # before PR #1814
def get_manager() -> "RelatedManager[MyModel]": ...
```
Usage after:
```python
from django_stubs_ext.db.models.manager import RelatedManager
def get_manager() -> RelatedManager[MyModel]: ...
```
1 parent 965d88a commit 997ac44
2 files changed
+23
-0
lines changedFile renamed without changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
0 commit comments