Skip to content

Conversation

prmukherj
Copy link
Collaborator

@prmukherj prmukherj commented Oct 12, 2025

Context

In the existing codebase, argument deprecations were handled inconsistently and often required writing repetitive, manual logic to warn users and remap deprecated arguments to their newer equivalents.
There was no unified or flexible way to deprecate multiple arguments at once, especially when multiple old arguments needed to map to one or more new arguments.
Additionally, existing deprecation decorators typically required developers to hardcode version strings and custom messages, leading to maintenance overhead and a higher chance of inconsistencies.

Change Summary

A new decorator, deprecate_arguments, is introduced with the following signature:

def deprecate_arguments(
    old_args: str | list[str],
    new_args: str | list[str],
    version: str,
    converter: Callable | None = None,
    warning_cls: type[Warning] = PyFluentDeprecationWarning,
) -> Callable:

A new decorator for deprecating function is also introduced.

def deprecate_function(
    version: str,
    new_func: str | None = None,
    warning_cls: type[Warning] = PyFluentDeprecationWarning,
) -> Callable:

Rationale

This decorator centralizes and simplifies how argument deprecations are declared and processed.
It reduces boilerplate, improves readability, and enforces consistency across the API.
By allowing grouped mappings, the design accommodates complex transitions (such as merging or splitting arguments).
Passing the full old_arg_list and new_arg_list to the converter provides more flexibility for complex transformation logic while keeping the default case straightforward.

Impact

Simplifies the process of marking arguments as deprecated.
Reduces risk of missing or inconsistent deprecation messages.
Provides an easy path for custom conversion logic between old and new APIs.

Example usage

>>> @deprecate_arguments(
>>>     old_args=["a", "b"],
>>>     new_args=["d", "e"],
>>>     version="3.0.0"
>>> )
>>> @deprecate_arguments(
>>>     old_args="c",
>>>     new_args="f",
>>>     version="3.0.0"
>>> )
>>> @deprecate_arguments(
>>>     old_args="x1",
>>>     new_args="z1",
>>>     version="3.0.0"
>>> )
>>> def example_func(**kwargs):
>>>     print(kwargs)

>>> example_func(a=1, b=2, c=3, x1=2, x2=4)

{'x2': 4, 'd': 1, 'e': 2, 'f': 3, 'z1': 2}
PyFluentDeprecationWarning: Arguments 'a', 'b' are deprecated; use 'd', 'e' instead.
  example_func(a=1, b=2, c=3, x1=2, x2=4)
PyFluentDeprecationWarning: Argument 'c' is deprecated; use 'f' instead.
  return wrapped_(*args_, **kwargs_)
PyFluentDeprecationWarning: Argument 'x1' is deprecated; use 'z1' instead.
  return wrapped_(*args_, **kwargs_)
>>>  def my_custom_converter(kwargs, old_args, new_args):
>>>      # Combine values of a, b into a tuple → d
>>>      values = tuple(kwargs.pop(arg) for arg in old_args if arg in kwargs)
>>>     if values:
>>>          kwargs[new_args[0]] = values
>>>     return kwargs

>>>  @deprecate_arguments(
>>>      old_args=["a", "b"],
>>>      new_args="d",
>>>      version="3.0.0",
>>>      converter=my_custom_converter,
>>>  )
>>>  @deprecate_arguments(
>>>      old_args="c",
>>>      new_args="e",
>>>      version="3.0.0",
>>>  )
>>>  def example_func(**kwargs):
>>>      print(kwargs)

>>>  example_func(a=1, b=2, c=3)

{'d': (1, 2), 'e': 3}
PyFluentDeprecationWarning: Arguments 'a', 'b' are deprecated; use 'd' instead.
  example_func(a=1, b=2, c=3)
PyFluentDeprecationWarning: Argument 'c' is deprecated; use 'e' instead.
  return wrapped_(*args_, **kwargs_)
>>>  @deprecate_function(version="3.0.0", new_func="new_add")
>>>  def old_add(a, b):
>>>      return a + b

>>>  def new_add(a, b):
>>>      return a + b + 10

>>>  old_add(1, 2)

PyFluentDeprecationWarning: Function 'old_add' is deprecated since version 3.0.0. Use 'new_add' instead. old_add(1, 2)

@prmukherj prmukherj requested a review from mkundu1 as a code owner October 12, 2025 15:54
@Copilot Copilot AI review requested due to automatic review settings October 12, 2025 15:54
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new deprecate_arguments decorator to centralize and simplify argument deprecation handling. The decorator supports grouped argument mappings, custom conversion logic, and consistent warning messages across the API.

  • Adds a flexible decorator that handles multiple deprecated arguments with automatic replacement
  • Supports both default 1-to-1 mapping and custom conversion functions for complex argument transformations
  • Provides consistent deprecation warnings with configurable warning classes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot added the enhancement Improve any current implemented feature label Oct 12, 2025
@prmukherj
Copy link
Collaborator Author

prmukherj commented Oct 12, 2025

Hi,

I have created this PR with the new signature. Please provide me your comments by referring to the example usages, based on your feedback will do improvements.

I have added some sample implementations in launcher, field_data and file_session code for reference.

Please note: method deprecator is yet to be implemented.

Thank you.

@Copilot Copilot AI review requested due to automatic review settings October 13, 2025 04:43
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Copilot Copilot AI review requested due to automatic review settings October 13, 2025 04:46
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Copilot Copilot AI review requested due to automatic review settings October 13, 2025 04:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

src/ansys/fluent/core/utils/deprecate_new.py:1

  • The _show_gui_to_ui_mode function is not defined in this file and is being called without being imported. This will cause a NameError at runtime.
"""Deprecate Arguments."""

src/ansys/fluent/core/utils/deprecate_new.py:1

  • The _version_to_dimension function is not defined in this file and is being called without being imported. This will cause a NameError at runtime.
"""Deprecate Arguments."""

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@seanpearsonuk seanpearsonuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prmukherj Will there be a follow-up stage to completely supersede the old version?

@prmukherj
Copy link
Collaborator Author

@prmukherj Will there be a follow-up stage to completely supersede the old version?

yes, I have created this PR just to get feedback on the design from everyone. Now I'll mark this as draft and make the shift as part of this PR only.

Thank you for your feedback @seanpearsonuk

@seanpearsonuk
Copy link
Collaborator

@prmukherj Will there be a follow-up stage to completely supersede the old version?

yes, I have created this PR just to get feedback on the design from everyone. Now I'll mark this as draft and make the shift as part of this PR only.

Thank you for your feedback @seanpearsonuk

OK, feel free to merge in stages too.

@prmukherj prmukherj requested a review from raph-luc October 14, 2025 12:16
@prmukherj
Copy link
Collaborator Author

>>> @deprecate_arguments(
>>>     old_args=["a", "b"],
>>>     new_args="d",
>>>     version="3.0.0",
>>>     converter=my_custom_converter,
>>> )
>>> @deprecate_arguments(
>>>     old_args="c",
>>>     new_args="e",
>>>     version="3.0.0",
>>>     converter=my_custom_converter,
>>> )
>>> def example_func(**kwargs):
>>>     print(kwargs)

@prmukherj prmukherj marked this pull request as draft October 14, 2025 13:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@seanpearsonuk
Copy link
Collaborator

@prmukherj The latest iteration looks a lot simpler and cleaner.

if isinstance(new_args, str):
new_args = [new_args]

# Validation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Validation

Comment on lines 60 to 61
# Default converter
def _default_converter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Default converter
def _default_converter(
def _default_converter(

return decorator
converter = converter or _default_converter

# Build reason message for @deprecated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Build reason message for @deprecated

Copy link
Member

@raph-luc raph-luc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a significant improvement to me, thanks for asking for review. Note the tests are failing, I didn't investigate if they are related to these changes or not

@Copilot Copilot AI review requested due to automatic review settings October 16, 2025 07:03
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Copilot Copilot AI review requested due to automatic review settings October 16, 2025 15:56
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@prmukherj prmukherj merged commit 887d345 into main Oct 17, 2025
36 checks passed
@prmukherj prmukherj deleted the maint/deprecate_arguments_updated branch October 17, 2025 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improve any current implemented feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecation decorators refactor

6 participants