Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django-stubs-ext: Export RelatedManager, ManyRelatedManager stub-only classes #1834

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions ext/django_stubs_ext/db/models/manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import TYPE_CHECKING

# Re-export stubs-only classes RelatedManger and ManyRelatedManager.
# These are fake, Django defines these inside function body.
if TYPE_CHECKING:
# noinspection PyUnresolvedReferences
from django.db.models.fields.related_descriptors import ManyRelatedManager as ManyRelatedManager

# noinspection PyUnresolvedReferences
from django.db.models.fields.related_descriptors import RelatedManager as RelatedManager

else:
from typing import Protocol, TypeVar

_T = TypeVar("_T")

# Define as `Protocol` to prevent them being used with `isinstance()`.
# These actually inherit from `BaseManager`.
class RelatedManager(Protocol[_T]):
pass

class ManyRelatedManager(Protocol[_T]):
pass