mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
Add Option to Dict.keys field
This commit is contained in:
parent
2f4fe8b380
commit
d7f5dadf47
1 changed files with 7 additions and 3 deletions
|
@ -227,12 +227,12 @@ class StructVisitor(TypeInfoEmitVisitor):
|
|||
if cons.fields:
|
||||
self.emit(f"{cons.name} {{", depth)
|
||||
for f in cons.fields:
|
||||
self.visit(f, parent, "", depth + 1)
|
||||
self.visit(f, parent, "", depth + 1, cons.name)
|
||||
self.emit("},", depth)
|
||||
else:
|
||||
self.emit(f"{cons.name},", depth)
|
||||
|
||||
def visitField(self, field, parent, vis, depth):
|
||||
def visitField(self, field, parent, vis, depth, constructor=None):
|
||||
typ = get_rust_type(field.type)
|
||||
fieldtype = self.typeinfo.get(field.type)
|
||||
if fieldtype and fieldtype.has_userdata:
|
||||
|
@ -240,7 +240,11 @@ class StructVisitor(TypeInfoEmitVisitor):
|
|||
# don't box if we're doing Vec<T>, but do box if we're doing Vec<Option<Box<T>>>
|
||||
if fieldtype and fieldtype.boxed and (not (parent.product or field.seq) or field.opt):
|
||||
typ = f"Box<{typ}>"
|
||||
if field.opt:
|
||||
if field.opt or (
|
||||
# Add `Option` to allow `Dict.keys` to contain `None` for dictionary unpacking
|
||||
# in a dict literal.
|
||||
constructor == "Dict" and field.name == "keys"
|
||||
):
|
||||
typ = f"Option<{typ}>"
|
||||
if field.seq:
|
||||
typ = f"Vec<{typ}>"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue