-
Notifications
You must be signed in to change notification settings - Fork 89
Prevent Required and NotRequired qualifiers together in TypedDict fields #447
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
Prevent Required and NotRequired qualifiers together in TypedDict fields #447
Conversation
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.
This looks great! I suggested a minor performance tweak, but definitely a good change.
pyrefly/lib/alt/solve.rs
Outdated
|
||
let has_required = ann.qualifiers.contains(&Qualifier::Required); | ||
let has_not_required = ann.qualifiers.contains(&Qualifier::NotRequired); | ||
if (qualifier == Qualifier::Required && has_not_required) |
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.
This code first checks if the required
is present (I think using a linear scan), but only uses that result if qualifier == Qualifier::Required
. It would be more efficient to inline has_required
and has_not_required
, then you only do the scan if you are on a relevant qualifier.
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.
Certainly! Thanks, I’ll update the code.
I'd expect |
Apologies for the oversight. The outputs were generated, but I missed committing them after running |
335a998
to
85f51b8
Compare
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
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.
Review automatically exported from Phabricator review in Meta.
@yangdanny97 merged this pull request in 0dc7768. |
Summary:
This PR resolves #414 by adding a check and testcase to prevent
Required
andNotRequired
from being used together as qualifiers in TypedDict fields.Changes:
solve.rs
to reject conflicting qualifiers.typed_dict.rs
to cover this case.