-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Converting positional arguments #64
Comments
Since Consider that def my_func(arg1, arg2=0):
pass
my_func(arg1=12, arg2=13) In Python 3.8 and above, the def my_func(arg1, /, arg2=0):
pass
my_func(arg1, arg2=13) When I minify this it turns into: def A(A,arg2=0):0
A(12,arg2=13) Notice that the separator has been removed and Even without positional-only parameters the parameter will be renamed inside the function without changing the definition, if the resulting code is smaller: def my_func(arg1, arg2=0):
arg1 + arg1 + arg1
my_func(12, arg2=13) Minifies to: def A(arg1,arg2=0):A=arg1;A+A+A
A(12,arg2=13) |
This makes sense, but wouldn't it already "break imports from other modules" that we are renaming my_func -> A? Maybe there could be a flag for "standalone files" that don't expect anybody to import them, and can thus be compressed extra? |
|
Right, but if I do use |
We can't assume that Imagine something like: mod1.py import mod2
def my_func(arg1, arg2):
return arg1 + arg2
mod2.process_with_callback(my_func) mod2.py def process_with_callback(f):
f(arg1=12, arg2=13) This is more common with parameter names for methods on objects being passed around, rather than functions themselves. But it's the same issue. There's also the problem that renaming the keyword parameter is really hard, even inside the same module. def arg2_name():
return 'arg2'
my_func(**{'ar' + 'g1': 12, arg2_name(): 13}) Python is too dynamic to do that safely. Perhaps there could be an option added to rename all parameters if the function calls are simple enough to allow it, and you can guarantee it won't be called from outside the module. With a big warning attached! |
The code
gets converted into
It seems
arg2
could have been replaced with something shorter?I have "Convert Positional-Only Arguments to Normal Arguments", but I guess that's just about removing the /?
The code
get transformed into the same minified form as the original.
The text was updated successfully, but these errors were encountered: