Skip to main content

Monkey-patching and extensions for django-stubs

Project description

Extensions and monkey-patching for django-stubs

Build Status Checked with mypy Gitter

This package contains extensions and monkey-patching functions for the django-stubs package. Certain features of django-stubs (i.e. generic django classes that don't define the __class_getitem__ method) require runtime monkey-patching, which can't be done with type stubs. These extensions were split into a separate package so library consumers don't need mypy as a runtime dependency (#526).

Installation

pip install django-stubs-ext

Usage

In your Django application, use the following code:

import django_stubs_ext

django_stubs_ext.monkeypatch()

This only needs to be called once, so the call to monkeypatch should be placed in your top-level settings. Real-life example can be found here.

Version compatibility

Since django-stubs supports multiple Django versions, this package takes care to only monkey-patch the features needed by your django version, and decides which features to patch at runtime. This is completely safe, as (currently) we only add a __class_getitem__ method that does nothing:

@classmethod
def __class_getitem__(cls, *args, **kwargs):
    return cls

To get help

For help with django-stubs, please view the main repository at https://github.com/typeddjango/django-stubs

We have a Gitter chat here: https://gitter.im/mypy-django/Lobby If you think you have a more generic typing issue, please refer to https://github.com/python/mypy and their Gitter.

Contributing

The django-stubs-ext package is part of the django-stubs monorepo. If you would like to contribute, please view the django-stubs contribution guide.

You can always also reach out in gitter to discuss your contributions!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_stubs_ext-5.0.0.tar.gz (9.4 kB view hashes)

Uploaded Source

Built Distribution

django_stubs_ext-5.0.0-py3-none-any.whl (8.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page