Repository navigation
Support for boxing SliceLiteral type #7714
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
Changes from 4 commits
0294ef3
06bc3bc
29abf88
4e2a179
1762ef2
8e2acaa
2b0a059
c7bcd41
31b4a8e
0a3502e
a476fa5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -379,6 +379,24 @@ def unbox_slice(typ, obj, c): | |
| sli.step = step | ||
| return NativeValue(sli._getvalue(), is_error=c.builder.not_(ok)) | ||
|
|
||
| @box(types.SliceLiteral) | ||
| def box_slice_literal(typ, val, c): | ||
| slice_lit = typ.literal_value | ||
| slice_fields = [] | ||
| for field_name in ("start", "stop", "step"): | ||
| field_obj = getattr(slice_lit, field_name) | ||
| field_val = ( | ||
| c.pyapi.make_none() | ||
| if field_obj is None | ||
| else c.pyapi.from_native_value( | ||
| types.literal(field_obj), field_obj, c.env_manager | ||
| ) | ||
| ) | ||
| slice_fields.append(field_val) | ||
| slice_val = c.pyapi.slice_new(*slice_fields) | ||
| for field_obj in slice_fields: | ||
| c.pyapi.decref(field_obj) | ||
| return slice_val | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like this might also work? @box(types.SliceLiteral)
def box_slice_literal(typ, val, c):
py_ctor, py_args = typ.literal_value.__reduce__()
serialized_ctor = c.pyapi.serialize_object(py_ctor)
serialized_args = c.pyapi.serialize_object(py_args)
ctor = c.pyapi.unserialize(serialized_ctor)
args = c.pyapi.unserialize(serialized_args)
obj = c.pyapi.call(ctor, args)
c.pyapi.decref(ctor)
c.pyapi.decref(args)
return objavoids needing to add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stuartarchibald I'm happy to update this code if you would like but I don't understand why this change is necessary/preferred. Is there a concern that creating native literals will have gaps/performs worse? |
||
|
|
||
| @unbox(types.StringLiteral) | ||
| def unbox_string_literal(typ, obj, c): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.