-
Notifications
You must be signed in to change notification settings - Fork 4
Extending print() #46
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requestwishlistStuff we want but there are more important thingsStuff we want but there are more important things
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestwishlistStuff we want but there are more important thingsStuff we want but there are more important things
Type
Fields
Give feedbackNo fields configured for issues without a type.
For now, we support 2 types of arguments to
print, which is our mapping forbpf_printk: normal strings and python f-strings.However, we do not support all the expressions that Python supports in their f-strings. All the arguments to the f-strings used in
printinside abpfchunk have to be named variables.So,
print("Hello")is allowedprint(f"My name is {name}")is allowedprint(f"1 + 1 is {1 + 1}")is NOT allowedprint(1 + 1)is NOT allowedI came across this while working on #40, where I am allocating a scratch space for bpf helper arguments that are passed as constants or binary operations, as they need to be stored somewhere and then passed.
The mechanism I use there is not directly compatible with
printdue to the way we handle f-strings inprint(f-strings can only occur as an arg toprint, so we don't bother separating it's handling logic out toexpr_pass).Of course, there are ways to overcome these, that is the reason I am marking this issue as a wishlist item. But we must do this some time in the future for the sake of a more pythonic syntax.