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
Add missing type annotations and require them in new code #61
base: main
Are you sure you want to change the base?
Conversation
I'd like to see if this fixes the issues mentioned in #58 (comment) |
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #61 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 328 333 +5
=========================================
+ Hits 328 333 +5
☔ View full report in Codecov by Sentry. |
Building docs fails with:
I think that this means that the class |
Yes, the underlying issue is that Django documents the https://docs.djangoproject.com/en/4.2/ref/models/fields/#django.db.models.Field This is also a part why this sphinx extension was created in the first place - it deals with such inconsistencies and monkeypatches the module path to its new location:
I'm not sure about this, but maybe the monkeypatch gets bypassed if the module is imported directly from its source? |
This adds type hints everywhere except unit tests.
All the annotations here were added via `ruff check --fix .`.
I don't think this code ever gets executed when type checking, right? |
Indeed, but type checking is not the problem, the doc build is. And during doc build, the monkeypatch should be executed, but somehow it does not apply to the stuff that sphinx is extracting from the type hints? 🤔 |
@WhyNotHugo And just because I could need this for another project: Do you know a tool to automatically convert the |
Ah, but maybe can the extension |
I did it manually. A tool that does this automatically would be superb.
I don't understand what this does. Sphinx already shows the types from type hints in the function signature by default. Example: https://django-afip.readthedocs.io/en/latest/api.html#django_afip.clients.get_client |
Apparently CI failed because codecov was down. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I found the culprit:
The patches are not correctly applied, because during docbuild, only the sphinxcontrib_django.roles
extension is enabled:
sphinxcontrib-django/docs/conf.py
Line 28 in f4dfbbd
"sphinxcontrib_django.roles", |
This means the patches are completely unused for our own docs. And there is no easy way to enable them without refactoring the structure of the extension, because the sphinxcontrib_django.docstrings
extension needs Django settings and cannot be used without a standalone Django installation.
But I guess it makes sense to extract the patches from there, since patches are also relevant for Django library documentations, not only for Django applications.
I will refactor the structure of the extension first and then revisit this PR later!
Short description
Add type annotations to all non-test code.
Also configure
ruff
to complain loudly if new code is missing annotations.