Skip to content
Ali Al-Ramadan edited this page Nov 14, 2026 · 2 revisions

The rules of the method stereotypes, the free-function stereotypes, and the class stereotypes hold in Python as in every language of Stereocode. This page gives the forms that the facts of these rules take in Python, the built-in lists that Stereocode reads for Python, and one labeled example of each stereotype. The page Python and JavaScript states in full how Stereocode reads data members, types, returned values, and calls in Python.

Language Facts

  • A method reaches its object through its first parameter, named self by convention. Every name that a method reaches through the object is a data member, unless the class or an ancestor in the archive defines a method or a class of that name.
  • A function without a return annotation returns None when no return gives a value and bool when each returned expression is Boolean by its form. Its return type is otherwise unknown. An unknown type counts as primitive.
  • A call of a class creates an object, also under a CapWords name that no free function of the archive has.
  • __init__ and __new__ get constructor, while __del__ gets destructor. Python has no copy constructor.
  • A body that holds only comments, a docstring, pass, and ... is empty.
  • The functions at the top level of a file, the static methods, and the class methods get the free-function stereotypes with the option -f.

Built-in Lists

Stereocode reads four built-in lists for Python. The list files of the options -p, -c, -s, and -q add entries to these lists under the section [Python], as the README states. Each list below opens with a click.

Primitive types (12 entries)

A type of this list makes no method a collaborator and no return type of a factory.

Any, bool, bytearray, bytes, complex, float, int, Literal, None, NoneType, object, str

Ignored calls (26 entries)

The rules ignore a call of these names. A name without a qualifier, such as print, is ignored only as the whole name of a call.

bool, breakpoint, bytearray, bytes, complex, dict, enumerate, exit, float, frozenset, int, isinstance, issubclass, len, list, print, quit, range, repr, reversed, set, str, sys.exit, tuple, type, zip

Specifiers and containers (44 entries)

Stereocode strips these entries from a written type before it reads the names of the type. A container counts by the types of its elements. Each entry is a regular expression, such as \.\.\. for ....

<, >, \.\.\., \|, AbstractSet, Annotated, AsyncGenerator, AsyncIterable, AsyncIterator, Awaitable, Callable, ChainMap, ClassVar, Collection, Coroutine, Counter, DefaultDict, defaultdict, Deque, deque, Dict, dict, Final, FrozenSet, frozenset, Generator, Iterable, Iterator, List, list, Mapping, MutableMapping, MutableSequence, MutableSet, Optional, OrderedDict, Sequence, Set, set, Tuple, tuple, Type, type, Union

Query methods (66 entries)

A call of these methods only reads the variable that the call is on.

as_integer_ratio, bit_count, bit_length, capitalize, casefold, center, conjugate, copy, count, decode, difference, encode, endswith, expandtabs, find, format, format_map, get, hex, index, intersection, is_integer, isalnum, isalpha, isascii, isdecimal, isdigit, isdisjoint, isidentifier, islower, isnumeric, isprintable, isspace, issubset, issuperset, istitle, isupper, items, join, keys, ljust, lower, lstrip, partition, removeprefix, removesuffix, replace, rfind, rindex, rjust, rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, symmetric_difference, title, to_bytes, translate, union, upper, values, zfill

Examples

Each example below is the declaration of an element from the stereotype cases of Stereocode, whose expected stereotypes are written by hand in @stereotype comments. Each link opens the case on the branch develop. The second column gives every stereotype of the element. A stereotype without an example has no case in Python.

Methods

Stereotype Stereotypes of the element Declaration
get get def is_calibrated(self) -> bool:
predicate predicate def is_larger(self, other: "Garage") -> bool:
property property def ring(self, width: float) -> float:
void-accessor void-accessor def read_celsius(self, values: list[float]) -> None:
set set def set_radius(self, radius: float) -> None:
command command def withdraw(self, amount: int) -> "Account":
non-void-command non-void-command def make_handler(self):
factory factory stateless def make_square(self, count: int) -> "Matrix":
collaborator get collaborator def get_pages(self, printer: Printer) -> int:
controller controller def send_first(self, printer: Printer) -> None:
wrapper wrapper def announce(self) -> None:
incidental incidental def greeting(self, name: str) -> str:
stateless stateless def fail(self):
empty empty def refresh(self) -> None:
constructor constructor def __init__(self, celsius: float):
copy-constructor No case
destructor destructor def __del__(self):
unclassified unclassified def detach(self, other):

TABLE 1. Examples of the method stereotypes in Python.

Free functions

Stereotype Stereotypes of the element Declaration
main main def main() -> None:
predicate predicate def is_even(value: int) -> bool:
property property def perimeter(side: float, sides: int) -> float:
global-command global-command def resize(cls, count: int) -> None:
command command def fill(values: list[int], value: int) -> None:
factory property factory def make_widget(style: int) -> Widget:
literal literal def path_separator():
wrapper wrapper def report(value: int) -> None:
empty empty def noop(value: int) -> None:
unclassified unclassified def show(value: int) -> None:

TABLE 2. Examples of the free-function stereotypes in Python, which the option -f assigns.

Types

Stereotype Stereotypes of the element Declaration
boundary boundary class Exporter:
commander minimal-entity commander class Counter:
controller controller class Spooler:
data-class data-class class Pair:
data-provider data-provider class Circle:
degenerate entity degenerate class Plugin:
empty empty class Tag:
entity entity boundary class Measure:
factory factory controller class WidgetFactory:
lazy-class lazy-class class Settings:
minimal-entity minimal-entity commander class Counter:
pure-controller pure-controller class Dispatcher:
small-class data-class small-class class Account:

TABLE 3. Examples of the class stereotypes in Python, where large-class, lazy-class, data-class, and small-class of a type of another kind take that kind in place of class, such as data-struct.

Clone this wiki locally