-
Notifications
You must be signed in to change notification settings - Fork 102
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
interested in adding typing (mypy) support? #198
Comments
upstream seems not super active so I sent an issue there and I'm going to plop stubs here for now mozilla/django-csp#198
Hi @asottile-sentry - been a while since you opened this, but I'm dusting off the project. Your suggestion makes sense, yeah. If you'd be up for sharing the |
Any updates on this? mypy checks are failing with
|
I started adding inline annotations but other things were higher priority -- we use this |
* Add basepython entries for pypy. This fixes running tox locally. * Fix the cpython version mapping in [gh-actions]. The github action tests for cpython versions are running against the latest Django, instead of the set of possible Django versions. * Add mypy for type checking * Handle case where config is None * Use getattr, setattr for dynamic attribute access - mypy complains when reading or setting a attribute that is not defined on the class, such as HttpRequest.csp_nonce. This updates the code to use getattr and setattr to access these dynamically added attributes and for Django settings. * Use tuples where requested - Both startswith() and parser.parse_statements take a tuple rather than a list. * Add type hints * Refactor ScriptTestBase - Althought the code `template.render(context)` looked similar, mypy complained that Django's Template could not take a dict. Rather than switch on types, refactor `make_context` and `make_template` into `render`, which hides the typing details between Django templates and extension templates like Jinja2. * Fix Sphinx doc generation without setuptools * Add `pip install -e ".[dev]"` * Update docs for typing, etc. * Add PEP 561 py.typed file * Bump Django dependency to 4.2+ * Replace `HttpResponse` type with `HttpResponseBase` * Update CHANGES file --------- Co-authored-by: Rob Hudson <robhudson@mozilla.com>
Type hints were added in #228. Thank you for the suggestion. |
this would allow users to typecheck their usage of this middleware -- it seems pretty simple (there's only a few public functions) and could be checked in CI with mypy
for now I'm creating some
.pyi
stubs in sentry which are enough for my use right now -- but it might be nice to share these more broadly via this packageThe text was updated successfully, but these errors were encountered: