Repository navigation
Report keyword arguments passed to NewType - #5752
seunghyun-24 wants to merge 3 commits into
Conversation
|
Hi @seunghyun-24! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
stroxler
left a comment
There was a problem hiding this comment.
Thanks @seunghyun-24!
This looks pretty good to me. There's a gap in our tooling where our auto-import flow (to turn PRs into diffs in the internal mirror) doesn't run for initial PRs from people who haven't yet signed the CLA.
Could you rebase this? That should trigger auto-import, and it's easier to review and merge once that runs.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
322eedb to
ab9f18a
Compare
|
This pull request has been imported. If you are a Meta employee, you can view this in D134357714. (Because this pull request was imported automatically, there will not be any future comments.) |
Summary
NewType("A", int, extra=True)was not reported, becausesynthesize_typing_new_typebound the keywords arguments without validating them.Following the suggestion in the issue, this change validates keyword arguments in the same way as functional
TypedDictdefinitions. SinceNewTypetakes no keyword arguments, every keyword is reported asinvalid-argument:extra=True→ Unrecognized keyword argumentextrainNewTypedefinition**kwargs→ Unpacking is not supported in NewType definitionThe
NewTypeis still created, so it can be used as a type after the error.Calls that don't have exactly two positional arguments (e.g.
NewType(name="A", tp=int)) continue to be handled by the regular call check as before.Fixes #5674
Test Plan
Added
test_new_type_unexpected_keywordinpyrefly/lib/test/new_type.rs. It covers a named keyword argument,**kwargs, and using theNewTypeas a type after the error.cargo test --lib -- test::new_typepasses.When running
test.pylocally,test::cycles::deep_phi_chain_term_exproverflows its stack on my machine. The same failure occurs on main without this change, so it appears unrelated.All other lib tests pass locally (
cargo test --lib -- --skip deep_phi_chain_term_expr).