Skip to content

Fix #595: Prevent TypedDict kwargs from overlapping with named parameters #665

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

iad1tya
Copy link

@iad1tya iad1tya commented Jul 11, 2025

Closes #595

This PR addresses issue #595 by adding a check in function.rs to prevent TypedDict keys in **kwargs (both direct TypedDict and Unpack[TypedDict]) from overlapping with named parameters, raising a BadFunctionDefinition error. The change is tested in typed_dict.rs with test_typed_dict_kwargs_overlap, covering direct TypedDict, Unpack[TypedDict], and a non-overlapping case. All tests pass, and test.py snapshots are included.

Changes:

  • Added overlap check in function.rs for Type::TypedDict and Type::Unpack with TypedDict inner type.
  • Updated typed_dict.rs with test_typed_dict_kwargs_overlap to verify both cases and a negative test.
  • Verified with cargo test and pyrefly check test.py.

@yangdanny97, please review and let me know if additional cases or changes are needed, especially for Unpack handling. Thanks!

@facebook-github-bot
Copy link
Contributor

Hi @iad1tya!

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!

@iad1tya
Copy link
Author

iad1tya commented Jul 11, 2025

Closes #595

This PR addresses issue #595 by adding a check in function.rs to prevent TypedDict keys in **kwargs (both direct TypedDict and Unpack[TypedDict]) from overlapping with named parameters, raising a BadFunctionDefinition error. The change is tested in typed_dict.rs with test_typed_dict_kwargs_overlap, covering direct TypedDict, Unpack[TypedDict], and a non-overlapping case. All tests pass, and test.py snapshots are included.

Changes:

Added overlap check in function.rs for Type::TypedDict and Type::Unpack with TypedDict inner type.
Updated typed_dict.rs with test_typed_dict_kwargs_overlap to verify both cases and a negative test.
Verified with cargo test and pyrefly check test.py.
@yangdanny97, please review and let me know if additional cases or changes are needed, especially for Unpack handling. Thanks!

@iad1tya iad1tya closed this Jul 11, 2025
@yangdanny97
Copy link
Contributor

Hm, something's off about the whitespace changes in the test file, the whole file looks changed.

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.

[feature] don't allow Unpacked TypedDict kwargs to overlap with any named parameter
3 participants