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

requirements: Add django-stubs. #18777

Merged
merged 5 commits into from
Oct 5, 2022
Merged

requirements: Add django-stubs. #18777

merged 5 commits into from
Oct 5, 2022

Commits on Oct 5, 2022

  1. typing: Use django-stubs' type annotations for QuerySet.

    We no longer need to annotate the type of objects returned
    from queries since django-stubs plugin infers that already.
    
    Signed-off-by: Zixuan James Li <p359101898@gmail.com>
    PIG208 committed Oct 5, 2022
    Configuration menu
    Copy the full SHA
    f146033 View commit details
    Browse the repository at this point in the history
  2. models: Implicitly type model fields with django-stubs.

    Previously, we type the model fields with explicit type annotations
    manually with the approximate types. This was because the lack of types
    for Django.
    
    django-stubs provides more specific types for all these fields that
    incompatible with our previous approximate annotations. So now we can
    remove the inline type annotations and rely on the types defined in the
    stubs. This allows mypy to infer the types of the model fields for us.
    
    Signed-off-by: Zixuan James Li <p359101898@gmail.com>
    PIG208 committed Oct 5, 2022
    Configuration menu
    Copy the full SHA
    d5359a7 View commit details
    Browse the repository at this point in the history
  3. requirements: Add django-stubs and configure plugin.

    Note that django_stubs_ext is required to be placed within common.in
    because we need the monkeypatched types in runtime; django-stubs
    itself is for type checking only.
    
    In the future, we would like to pin to a release instead of a git
    revision, but several patches we've contributed upstream have not
    appeared in a release yet.
    
    We also remove the type annotation for RealmAuditLog.event_last_message_id
    here instead of earlier because type checking fails otherwise.
    
    Fixes zulip#11560.
    PIG208 authored and timabbott committed Oct 5, 2022
    Configuration menu
    Copy the full SHA
    b7d8c81 View commit details
    Browse the repository at this point in the history
  4. typing: Import StrPromise alias from django_stubs_ext.

    This saves us from using a conditional import.
    
    Signed-off-by: Zixuan James Li <p359101898@gmail.com>
    PIG208 authored and timabbott committed Oct 5, 2022
    Configuration menu
    Copy the full SHA
    9dd556c View commit details
    Browse the repository at this point in the history
  5. typing: Import ValuesQuerySet alias from django_stubs_ext.

    This saves us from using a conditional import.
    
    Signed-off-by: Zixuan James Li <p359101898@gmail.com>
    PIG208 authored and timabbott committed Oct 5, 2022
    Configuration menu
    Copy the full SHA
    7c167be View commit details
    Browse the repository at this point in the history