Skip to content

Report keyword arguments passed to NewType - #5752

Open
seunghyun-24 wants to merge 3 commits into
pyrefly-org:mainfrom
seunghyun-24:fix/newtype-unexpected-kwargs
Open

seunghyun-24 wants to merge 3 commits into
pyrefly-org:mainfrom
seunghyun-24:fix/newtype-unexpected-kwargs

Conversation

@seunghyun-24

@seunghyun-24 seunghyun-24 commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

NewType("A", int, extra=True) was not reported, because synthesize_typing_new_type bound the keywords arguments without validating them.

Following the suggestion in the issue, this change validates keyword arguments in the same way as functional TypedDict definitions. Since NewType takes no keyword arguments, every keyword is reported as invalid-argument:

  • extra=True → Unrecognized keyword argument extra in NewType definition
  • **kwargs → Unpacking is not supported in NewType definition

The NewType is 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

  • I am a human, and I fully understand the code I am submitting.

Test Plan

Added test_new_type_unexpected_keyword in pyrefly/lib/test/new_type.rs. It covers a named keyword argument, **kwargs, and using the NewType as a type after the error.

cargo test --lib -- test::new_type passes.

When running test.py locally, test::cycles::deep_phi_chain_term_expr overflows 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).

Copilot AI balanced review requested due to automatic review settings November 24, 2026 15:52
@meta-cla

meta-cla Bot commented Nov 24, 2026

Copy link
Copy Markdown

Hi @seunghyun-24!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@seunghyun-24 seunghyun-24 changed the title Fix/newtype unexpected kwargs Report keyword arguments passed to NewType Nov 24, 2026
@meta-cla

meta-cla Bot commented Nov 24, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@stroxler stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@meta-codesync

meta-codesync Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.)

This branch has not been deployed

No deployments
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.

NewType() accepts unexpected keyword arguments

3 participants