liveBook · Manning

Type signature

As explained in Python How-To

A function signature is the interface-level description of a function's name and parameters, and in some languages its return information.

A function signature is the interface-level shape of a function: its name and the arguments callers can provide. In Python, a signature can evolve without disrupting existing callers when a new parameter receives a suitable default value. section 6.1.2 section 1.1.1

Adding an optional note

Suppose complete_task initially accepts only task. Adding note changes the interface, but defining note="" preserves the old call complete_task(task) while allowing callers to provide a note. This keeps existing code working and reduces repetitive empty-string arguments. section 6.1.2

def complete_task(task, note=""):
   task.status = "completed"
   task.note = note
   print(f"{task.title}'s status: completed; note: {note}")

Use the updated signature to make note optional while retaining the expanded functionality. section 6.1.2

complete_task(task)

Call the function with its original argument list; the default supplies the omitted note. section 6.1.2

When designing or reviewing a signature:

  • Choose parameter names that help readers understand what the function does. section 1.1.1
  • Prefer defaults when the common use case has a clear automatic value. section 6.1.2
  • Preserve the existing calling signature when extending a function, where practical. section 6.1.2

How Python How-To covers it

How deep it goes
Explains signatures through naming and default parameters, but does not descend into formal signature metadata or execution internals.
Examples
Uses complete_task with task and note arguments, including an omitted note resolved to an empty string.
What it assumes
Assumes basic familiarity with Python functions, arguments, and function calls; teaches interface readability and compatible parameter changes.
What you can do after
Apply Python default arguments to extend functions while keeping common calls short and existing calls operational.
How it connects
Connects function signatures with default arguments, application programming interfaces, backward compatibility, readability, and maintainability.

Also explained in

Compare how 8 books explain type signature →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python How-To. The section links point to the parts of the book it draws on.