Skip to content

CG-10921: Dict Merging + Unwrap Fixes#748

Open
tawsifkamal wants to merge 2 commits intodevelopfrom
tawsif/ts-dict
Open

CG-10921: Dict Merging + Unwrap Fixes#748
tawsifkamal wants to merge 2 commits intodevelopfrom
tawsif/ts-dict

Conversation

@tawsifkamal
Copy link
Copy Markdown
Contributor

  • Merge python dicts or javascript objects together (both normal keys and spread operators)

  • Dict.merge(**args: str | Dict) accepts args of str | Dict object

  • Calling unwrap on a Dict object will unwrap all spread objects in the dictionary/object which are denoted as the Unpack object

  • Dict.unpack -> Dict.unpacks solves the issue when there are multiple spreak operators so we capture all of them

  • Raises error if duplicate keys are present in python. Also recursively travels up spread operators to find duplicate keys

Examples

# Python
dict1.merge(dict2, dict3)  # Multiple dicts
dict1.merge("{'a': 1, **base1}", "{'b': 2}")       # With spread operator and strings

# TypeScript
dict1.merge(dict2, dict3, "{x: 1}", "{y: 2}")      # Multiple objects
dict1.merge("{a: 1, ...base1}", "{b: 2}")          # With spread operator

To find the spread objects you must do the following to loop over everything. These apis were already existing btw

for child in dict1.children
     print(child) # this will include all of the keys and the unpacked 

@tawsifkamal tawsifkamal requested review from a team and codegen-team as code owners March 5, 2025 01:23
@tawsifkamal tawsifkamal changed the title Tawsif/ts dict CG-10921: Dict Merging + Unwrap Fixes Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant