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

mypy plugin: More precisely detect when fields are required. #4086

Conversation

richardxia
Copy link
Contributor

@richardxia richardxia commented May 18, 2022

Change Summary

The mypy plugin would previously incorrectly determine that a field was
not required in a few scenarios where the field really is required. This
specifically affected cases when the Field() function is used, where
the plugin assumed that the first argument would always be default.

This changes the code to examine each argument more closely, and it now
properly handles several more scenarios where the default is explicitly
named or when the default_factory named argument is used.

Related issue number

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100% (Coverage was not at 100% to begin with for me, but the coverage did not drop after I made my changes)
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

The mypy plugin would previously incorrectly determine that a field was
not required in a few scenarios where the field really is required. This
specifically affected cases when the `Field()` function is used, where
the plugin assumed that the first argument would always be `default`.

This changes the code to examine each argument more closely, and it now
properly handles several more scenarios where the default is explicitly
named or when the default_factory named argument is used.
@richardxia
Copy link
Contributor Author

Whoops, I misunderstood the last item on the checklist. Please review when you have the time.

@samuelcolvin
Copy link
Member

great, thanks so much.

@richardxia
Copy link
Contributor Author

Thanks!

@richardxia richardxia deleted the fix-mypy-detection-of-required-fields branch August 8, 2022 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants