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

improve mypy typing #600 #620

Merged
merged 1 commit into from
Dec 11, 2023
Merged

improve mypy typing #600 #620

merged 1 commit into from
Dec 11, 2023

Conversation

tfranzel
Copy link
Owner

Type improvements. This will fix some of the mypy --strict flags. Green for the following flags. Commented out flags still fail.

mypy --config-file tox.ini drf_spectacular \
--warn-unused-configs \ 
--strict-equality \
--no-implicit-optional \ 
--warn-redundant-casts \
--disallow-untyped-decorators \ 
--disallow-subclassing-any \ 
--warn-unused-ignores \ 
#--check-untyped-defs \
#--warn-return-any \
#--no-implicit-reexport \
#--disallow-incomplete-defs \
#--disallow-any-generics \
#--disallow-untyped-calls \
#--disallow-untyped-defs \

@codecov
Copy link

codecov bot commented Dec 19, 2021

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (4ef322c) 98.63% compared to head (e0f4dd6) 98.61%.

Files Patch % Lines
drf_spectacular/openapi.py 93.75% 3 Missing ⚠️
drf_spectacular/plumbing.py 98.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #620      +/-   ##
==========================================
- Coverage   98.63%   98.61%   -0.02%     
==========================================
  Files          71       71              
  Lines        8626     8647      +21     
==========================================
+ Hits         8508     8527      +19     
- Misses        118      120       +2     

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

@johnthagen
Copy link
Contributor

I'm sure you know this already, but just FYI you can put these settings into the Mypy config file too to avoid having to pass them each time into the command line.

@tfranzel
Copy link
Owner Author

yeah thx, i know. had this command in a shell script for playing around, but at some point it should be included in tox.ini for sure.

@sshishov
Copy link

sshishov commented Aug 2, 2023

When the change is going to be released?

@tfranzel
Copy link
Owner Author

tfranzel commented Aug 2, 2023

@sshishov what exactly is your use-case in benefiting from this PR?

we will likely never be able to pass full--strict without hundreds of type: ignore due to the dynamic nature of this package. It is good to have nonetheless, but the user is likely only to really benefit from changes to utils.py

@johnthagen
Copy link
Contributor

As a user of utils.py I'd welcome this PR. 😄

@tfranzel
Copy link
Owner Author

tfranzel commented Aug 6, 2023

in that case I will revisit this PR when I have some spare time.

@sshishov
Copy link

sshishov commented Aug 6, 2023

Hello @tfranzel and @johnthagen . My use case is the subclass of AutoSchema and extend it to use with drf-rw-serializers which we have in Blueprints. As we are using mypy with almost strict configuration, any code which is called untyped objects or subclassed from untyped objects, are warned.

Definitely we can add the ignore and completely abandon typing hints but we would like to use the typing hints as it make the coding more fun and easy.

Do not get me wrong, guys, just adding typing is beneficial as IDE start helping a lot in that case. Also typed code much easier to read and extend as you know that are the parameters, what their types and kind of how to use them.

Thank you! And sorry for the longread...

@tfranzel tfranzel force-pushed the improved_typing branch 4 times, most recently from bbf1bc1 to f666620 Compare December 10, 2023 20:10
@tfranzel tfranzel merged commit eea552d into master Dec 11, 2023
68 checks passed
@tfranzel tfranzel deleted the improved_typing branch December 11, 2023 01:13
@tfranzel
Copy link
Owner Author

Hey guys, so I revised this PR again. I think it is a lot better now and a step in the right direction, but not perfect and not complete by any stretch of the imagination. not sure exactly how far we can go further, but passing --strict is imho almost impossible due to the dynamic nature of the package.

any further iteration should be smaller though. feel free to give feedback.

@johnthagen
Copy link
Contributor

johnthagen commented Dec 28, 2023

@tfranzel Wanted to report I just updated to drf-spectacular 0.27.0 and was able to remove a bunch of # type: ignore comments because of this, thanks!

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.

None yet

3 participants