Skip to content
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

[WIP][SPARK-47854][PYTHON][CONNECT] Avoid shadowing python built-ins in python function variable naming #49326

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

skanderboudawara
Copy link

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

# breaks:
foo(str="x", bar="y")

# okay:
foo("x", bar="y")

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

@@ -339,10 +339,10 @@ def coalesce(*cols: "ColumnOrName") -> Column:
coalesce.__doc__ = pysparkfuncs.coalesce.__doc__


def expr(str: str) -> Column:
def expr(expression: str) -> Column:
Copy link
Member

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 ..

Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants