{"record":{"id":"04e2f075751186a2","repo":"pola-rs/polars","slug":"func-name-r-received-both-old-name-r-and","errorCode":null,"errorMessage":"`{func_name!r}` received both `{old_name!r}` and `{new_name!r}` as arguments; `{old_name!r}` {is_deprecated}, use `{new_name!r}` instead","messagePattern":"`(.+?)` received both `(.+?)` and `(.+?)` as arguments; `(.+?)` (.+?), use `(.+?)` instead","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/deprecation.py","lineNumber":158,"sourceCode":"def _rename_keyword_argument(\n    old_name: str,\n    new_name: str,\n    kwargs: dict[str, object],\n    func_name: str,\n    version: str,\n    mapper: Callable[[object], object],\n) -> None:\n    \"\"\"Rename a keyword argument of a function.\"\"\"\n    if old_name in kwargs:\n        if new_name in kwargs:\n            is_deprecated = (\n                f\"was deprecated in version {version}\" if version else \"is deprecated\"\n            )\n            msg = (\n                f\"`{func_name!r}` received both `{old_name!r}` and `{new_name!r}` as arguments;\"\n                f\" `{old_name!r}` {is_deprecated}, use `{new_name!r}` instead\"\n            )\n            raise TypeError(msg)\n\n        in_version = f\" in version {version}\" if version else \"\"\n        issue_deprecation_warning(\n            f\"the argument `{old_name}` for `{func_name}` is deprecated. \"\n            f\"It was renamed to `{new_name}`{in_version}.\"\n        )\n        kwargs[new_name] = mapper(kwargs.pop(old_name))\n\n\ndef deprecate_nonkeyword_arguments(\n    allowed_args: list[str] | None = None, message: str | None = None, *, version: str\n) -> IdentityFunction:\n    \"\"\"\n    Decorator for deprecating the use of non-keyword arguments in a function.\n\n    Use as follows:\n\n        @deprecate_nonkeyword_arguments(allowed_args=[\"self\", \"val\"], version=\"1.0.0\")","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/_utils/deprecation.py#L140-L176","documentation":"rename_kwarg implements polars' parameter renames: if a caller passes only the deprecated keyword they get a DeprecationWarning and the value is forwarded; if they pass BOTH the old and the new keyword, the intent is ambiguous and polars raises TypeError immediately telling you which name to keep.","triggerScenarios":"Calling a renamed function with both names, e.g. df.write_csv(file=f, path=\"out.csv\") or any wrapper that sets the new kwarg while forwarding **kwargs that still contain the old one.","commonSituations":"Half-finished migration after a polars major upgrade; utility wrappers doing fn(**kwargs, new_name=default) while callers still send old_name; IDE auto-complete inserting the new name next to the old one.","solutions":["Delete the deprecated argument from the call, keeping only the new name.","In wrappers, pop the old key before injecting the new one: kwargs.setdefault(new_name, kwargs.pop(old_name, default)).","Read the deprecation warning issued earlier — it names both the old and new parameter."],"exampleFix":"// before\ndf.write_csv(path=\"out.csv\", file=\"out.csv\")  # both names -> TypeError\n\n// after\ndf.write_csv(\"out.csv\")  # new-style positional/new name only","handlingStrategy":"validation","validationCode":"def forward_renamed_kwargs(func, kwargs: dict, old_name: str, new_name: str):\n    if old_name in kwargs and new_name in kwargs:\n        raise TypeError(f\"pass only one of {old_name!r}/{new_name!r} to {func.__name__}\")\n    if old_name in kwargs:\n        kwargs[new_name] = kwargs.pop(old_name)\n    return func(**kwargs)","typeGuard":null,"tryCatchPattern":"try:\n    result = fn(**kwargs)\nexcept TypeError as e:\n    if \"received both\" in str(e) and \"instead\" in str(e):\n        import re\n        m = re.search(r\"received both `(\\w+)` and `(\\w+)`\", str(e))\n        if m:\n            kwargs.pop(m.group(1), None)  # drop deprecated name, retry\n            result = fn(**kwargs)\n        else:\n            raise\n    else:\n        raise","preventionTips":["Finish parameter migrations in one commit instead of carrying both names.","Never inject the new kwarg while forwarding **kwargs that may contain the old one.","Treat DeprecationWarnings as errors in CI so renames surface before the TypeError does."],"tags":["deprecation","kwargs","migration","breaking-change"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}