Skip to content

Conversation

@leaderofARS
Copy link

@leaderofARS leaderofARS commented Dec 4, 2025

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