-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
[SPARK-47854][PYTHON][CONNECT] Avoid shadowing python built-ins in python function variable naming #49326
base: master
Are you sure you want to change the base?
[SPARK-47854][PYTHON][CONNECT] Avoid shadowing python built-ins in python function variable naming #49326
Conversation
@@ -339,10 +339,10 @@ def coalesce(*cols: "ColumnOrName") -> Column: | |||
coalesce.__doc__ = pysparkfuncs.coalesce.__doc__ | |||
|
|||
|
|||
def expr(str: str) -> Column: | |||
def expr(expression: str) -> Column: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually a breaking change if users use this API via kwargs ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall I add to keep both versions?
@overload
def expr(str: str) -> Column: …
Or else I create a decorator for future releases like so
from functools import wraps
def deprecated_param(old_param: str, new_param: str):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
if old_param in kwargs:
import warnings
warnings.warn(f"'{old_param}' is deprecated, use '{new_param}' instead", DeprecationWarning)
kwargs[new_param] = kwargs.pop(old_param)
return func(*args, **kwargs)
return wrapper
return decorator
@deprecated_param("str", "expression")
def expr(expression: str): ...
what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do but i feel like deprecating the parameter is too much too. Shadowing the builtin names are not nice but it won't affect end users anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey,
I think my decorator needs another update. Since we can deprecate more than one parameter, I’m wondering if it makes sense to use a dictionary or maybe something else.
On the consistency side, all the new functions since version 3.3 use “col” instead of “str” for parameters. It feels like harmonizing everything would be a good move, but as you mentioned, it could be a breaking change for folks using keyword arguments.
What do you think?
Should we wait for more opinions on this topic ?
What changes were proposed in this pull request?
Change all the functions parameters shadowing python built-in to a distinguished ones.
Why are the changes needed?
As mentionned in the Jira ticket
Does this PR introduce any user-facing change?
Yes.
How was this patch tested?
Github actions
Was this patch authored or co-authored using generative AI tooling?
No