Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove redundant else in activations.py#42742

Open
leaderofARS wants to merge 1 commit into
huggingface:mainfrom
leaderofARS:fix-redundant-else-clean
Open

Remove redundant else in activations.py#42742
leaderofARS wants to merge 1 commit into
huggingface:mainfrom
leaderofARS:fix-redundant-else-clean

Conversation

@leaderofARS

Copy link
Copy Markdown
Contributor

Remove Redundant Else Block in get_activation()

Fixes #42621

This PR removes a redundant else block in get_activation() in src/transformers/activations.py. The else was unnecessary because the if branch already returned, and keeping it went against the project's preferred early-return style.

Previous Control Flow

def get_activation(activation_string):
    if activation_string in ACT2FN:
        return ACT2FN[activation_string]
    else:
        raise KeyError(f"function {activation_string} not found in ACT2FN mapping {list(ACT2FN.keys())}")

Updated Control Flow

def get_activation(activation_string):
    if activation_string in ACT2FN:
        return ACT2FN[activation_string]
    raise KeyError(f"function {activation_string} not found in ACT2FN mapping {list(ACT2FN.keys())}")

Summary

  • Pure cleanup (no behavior change)
  • Simplifies logic and matches HF style
  • All style & repo checks pass

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant