Skip to content

Make parameter mandatory

Convert an optional function parameter back into a required parameter. BetterPy removes the default value from the signature so callers must provide an argument explicitly.

How to invoke

Place the caret on an optional parameter and use ⌥⏎ / Alt+Enter -> "BetterPy: Make mandatory".

Example

def greet(name: str, title: str = ""):
    return f"{title} {name}"

becomes:

def greet(name: str, title: str):
    return f"{title} {name}"

What it supports

  • Function and method parameters with simple default values.
  • Typed and untyped parameters.
  • Regular project Python files.
  • Keeping annotations, decorators, and the surrounding function body unchanged.

What it deliberately avoids

  • Parameters without a default value.
  • *args, **kwargs, and generated parameters.
  • Changes to call sites. After applying the intention, inspect callers and update any that relied on the removed default.
  • Files outside your own project sources.

Notes

  • This is a signature-editing intention, not a full call-site migration.
  • The feature is gated by the Make parameter mandatory setting under Settings | BetterPy | Refactoring & code transformations | Arguments.