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

Typechecking on API URLs (mostly error suppression) #4915

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

sergei-maertens
Copy link
Member

No description provided.

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.62%. Comparing base (486d9cb) to head (07ef1ca).
Report is 15 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4915   +/-   ##
=======================================
  Coverage   96.62%   96.62%           
=======================================
  Files         760      760           
  Lines       25818    25819    +1     
  Branches     3382     3382           
=======================================
+ Hits        24947    24948    +1     
  Misses        606      606           
  Partials      265      265           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

It's doing a lot of duck-typing and does not play nice with the types
defined in django-stubs, which would ideally be protocols rather than
named types for these kind of things.

However, we let the decorator_include declare the type it wants in
the path arguments, and apply a cast around the custom class to
silence the remaining type checker warnings.

The most important thing here is that the input types for decorator_include
are checked and our urls.py modules aren't unusable.
@sergei-maertens sergei-maertens force-pushed the cleanup/typecheck-api-urls branch from c3462e3 to 07ef1ca Compare December 17, 2024 14:05
@sergei-maertens sergei-maertens marked this pull request as ready for review December 17, 2024 14:06
@@ -13,6 +14,9 @@

from openforms.typing import AnyRequest

if TYPE_CHECKING:
from django.conf.urls import _IncludedURLConf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it good that we are using Django's private API here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not actually private API, but types defined by django-stubs! this import does not exist at runtime, and that's why it's guarded by the if TYPE_CHECKING: in combination with from __future__ import annotations

@sergei-maertens sergei-maertens merged commit d0e1ac2 into master Dec 18, 2024
33 of 36 checks passed
@sergei-maertens sergei-maertens deleted the cleanup/typecheck-api-urls branch December 18, 2024 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants