liveBook · Manning

Type signature

As explained in Software Design for Python Programmers

A function signature is the specification consisting of a function's name and the number, datatypes, and order of its parameters.

A function or method signature specifies its name, parameter count, parameter datatypes, parameter order, and return datatype. Parameter names are not part of the signature. section 7.6 section 4.3

Same signature, different subclass behavior

Item._cost(regular_price, weight) and OrganicItem._cost(organic_price, weight) have the same signature because their names, parameter counts, and parameter order match; changing parameter names does not prevent overriding. Python normally omits parameter and return datatypes, while statically typed languages include them. section 7.1.1

Use signatures to communicate class design at different levels of detail:

  • In a UML class diagram, show each method’s name, parameter datatypes, and return datatype when that detail matters. section 4.3
  • Use matching signatures to enable method overriding and runtime polymorphism between superclass and subclass methods. section 7.1.1
  • Distinguish overloaded functions by keeping the same name but changing their other signature elements. section 7.6

How Software Design for Python Programmers covers it

How deep it goes
Defines signature components, contrasts Python with statically typed languages, and applies matching signatures to overriding.
Examples
Uses Item and OrganicItem methods, UML class diagrams, and Python examples to demonstrate matching and differing signatures.
What you can do after
Apply method overriding and document class methods with appropriately detailed UML signatures.
How it connects
Connects signatures to UML class diagrams, method overriding, polymorphism, inheritance, and overloaded functions.

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 Software Design for Python Programmers. The section links point to the parts of the book it draws on.