PCPP1 key terms
PCPP1 · Get comfortable with the vocabulary.
- metaclass
- Related: type.__new__, abstract base class, __init_subclass__
A class whose instances are themselves classes. It controls how a class object is created and can inject or modify methods and attributes at class-creation time, most often by subclassing type.
- __init_subclass__
- Related: metaclass, class decorator
A classmethod-like hook defined on a parent class that runs whenever a subclass is created. It lets a base class validate or configure subclasses without writing a custom metaclass.
- abstract base class
- Related: @abstractmethod, virtual subclass, metaclass
A class that cannot be instantiated until its abstract methods are overridden. Built with the abc module, it documents an interface and enforces implementation through the ABCMeta metaclass and @abstractmethod.
- @abstractmethod
- Related: abstract base class, NotImplementedError
A decorator marking a method that subclasses must override. Instantiating a class that still has unimplemented abstract methods raises TypeError at runtime.
- virtual subclass
- Related: abstract base class, __subclasshook__
A class registered with an abstract base class via register() or subclasshook so that isinstance and issubclass report it as a subclass without inheritance. No methods are actually inherited.
- __subclasshook__
- Related: virtual subclass, abstract base class
A classmethod on an abstract base class that lets issubclass decide membership structurally, for example by checking for a particular method name, instead of relying on explicit registration.
- method resolution order
- Related: super(), cooperative multiple inheritance
The linearized order Python uses to look up attributes across a class's inheritance graph. Computed by the C3 algorithm and exposed as the mro attribute; it resolves diamond inheritance deterministically.
- super()
- Related: method resolution order, cooperative multiple inheritance
A built-in returning a proxy that delegates attribute lookup to the next class in the method resolution order. In cooperative multiple inheritance it forwards calls along the chain rather than jumping to a fixed parent.
- cooperative multiple inheritance
- Related: super(), method resolution order
A design pattern where each class in a hierarchy calls super() with matching signatures so every sibling's method runs exactly once, following the method resolution order.
- descriptor
- Related: property, data descriptor, __set_name__
An object defining get, set, or delete that customizes attribute access on a class. Functions, properties, classmethods, and staticmethods are all descriptors.
- data descriptor
- Related: descriptor, property
A descriptor that defines set or delete, giving it priority over entries in the instance dict during attribute lookup. Functions are non-data descriptors because they only define get.
- __set_name__
- Related: descriptor, metaclass
A hook called automatically on every descriptor in a class body when the owning class is created, receiving the owner class and the attribute name. Useful for caching the attribute name.
- property
- Related: descriptor, data descriptor
A built-in descriptor that turns getter, setter, and deleter methods into managed attributes. Accessing the attribute invokes the getter, so validation and computed values stay transparent to callers.
- __slots__
- Related: descriptor, __dict__
A class attribute listing permitted instance attribute names, replacing the per-instance dict with fixed storage. It reduces memory use and blocks assignment of undeclared attributes.
- __dict__
- Related: __slots__, descriptor
The namespace dictionary holding an object's writable attributes. Instances normally have one; classes use it for their own attributes, and it is absent on instances of classes defining slots.
- dunder method
- Related: operator overloading, __call__
A special method with double leading and trailing underscores, such as len or add, invoked implicitly by Python syntax and built-in functions rather than called directly by name.
- operator overloading
- Related: dunder method, functools.total_ordering
Implementing dunder methods like add, eq, or lt so that operators and comparisons work on user-defined types with intuitive syntax and predictable semantics.
- functools.total_ordering
- Related: operator overloading
A class decorator that fills in the remaining rich comparison methods (le, gt, ge) once a class defines eq plus one of lt, le, gt, or ge.
- __call__
- Related: dunder method, closure
A dunder method that makes instances callable like functions. Defining it lets an object hold configuration state while still being invoked with parentheses.
- closure
- Related: nonlocal, __call__
A nested function that captures and retains variables from its enclosing scope after that scope has finished executing. Captured names are exposed through closure and read via nonlocal.
- nonlocal
- Related: closure, global
A statement letting a nested function rebind a name from an enclosing function scope instead of creating a new local variable. It does not reach module or global scope.
- class decorator
- Related: __init_subclass__, metaclass
A callable applied to a class definition with the @ syntax that receives the class object and returns a replacement, often used to add methods or register classes in a registry.
- PEP 8
- Related: linter, docstring
The official style guide for Python code, covering naming conventions, indentation, imports, blank lines, and line length. Compliance is checked by linters such as flake8 or ruff.
- PEP 257
- Related: docstring, PEP 8
The convention for docstrings: a one-line summary ending with a period, a blank line, then details for multi-line docstrings. It defines where docstrings belong and how tools read them.
- docstring
- Related: PEP 257, Sphinx
A string literal placed as the first statement of a module, class, or function, stored in doc. It documents intent and is extracted by help() and documentation generators.
- type hint
- Related: mypy, typing.Optional
An annotation on a parameter, return value, or variable describing the expected type, such as list[int]. Hints are not enforced at runtime; static checkers and tools read them.
- mypy
- Related: type hint, typing.Protocol
A static type checker that analyzes annotations without running the code, reporting incompatible assignments and calls. It supports gradual typing, so unannotated code is largely ignored.
- typing.Optional
- Related: type hint, mypy
A typing construct meaning a value is either the given type or None. Modern syntax writes it as X | None; it flags callers to handle the absent-value case.
- typing.Protocol
- Related: duck typing, abstract base class
A base class for defining structural interfaces. A class satisfies a Protocol by having matching methods and attributes, without inheriting from it, enabling static duck typing.
- duck typing
- Related: typing.Protocol, EAFP
A style where an object's suitability depends on the methods and attributes it actually has, not on its declared type. Python resolves such behavior at runtime.
- EAFP
- Related: try/except/else/finally, duck typing
Easier to Ask Forgiveness than Permission: a Python idiom of attempting an operation and handling the resulting exception, rather than pre-checking conditions as in LBYL style.
- try/except/else/finally
- Related: EAFP, context manager
A compound statement where except handles matching exceptions, else runs only when no exception occurred, and finally always runs for cleanup. Order matters and bare except clauses hide bugs.
- context manager
- Related: contextlib.contextmanager, try/except/else/finally
An object implementing enter and exit so it can be used in a with statement. It guarantees setup and teardown, such as closing files or releasing locks, even when exceptions occur.
- contextlib.contextmanager
- Related: context manager
A decorator turning a generator function into a context manager. Code before yield is setup, the yielded value becomes the as-target, and code after yield is teardown.
- linter
- Related: PEP 8, formatter
A tool that statically inspects source code for style violations, unused imports, and suspicious constructs without executing it. Common Python examples are ruff, flake8, and pylint.
- formatter
- Related: linter, PEP 8
A tool that rewrites source code to a consistent layout automatically, such as black or ruff format. It removes debates over spacing while leaving semantics unchanged.
- venv
- Related: pip, requirements.txt
The standard-library module for creating isolated environments with their own interpreter link and site-packages, so project dependencies do not clash across projects.
- requirements.txt
- Related: venv, pip
A plain-text file listing package specifications, optionally pinned with ==, that pip install -r reads to reproduce an environment. Pinning versions makes builds reproducible.
- tkinter
- Related: geometry manager, event binding, mainloop
Python's bundled GUI toolkit wrapping Tcl/Tk. It provides widgets, geometry managers, and an event loop through mainloop(), requiring no third-party installation.
- mainloop
- Related: event binding, tkinter
The blocking call that starts a GUI application's event loop, dispatching user input and redraw events until the window closes. Code after it runs only after the loop exits.
- geometry manager
- Related: tkinter, event binding
A mechanism deciding widget size and placement inside a container. Tkinter offers pack, grid, and place; mixing pack and grid in one container causes layout errors.
- event binding
- Related: mainloop, callback
Associating a callback with a user action, such as a click or keypress, using bind() or the command option. The callback runs later, inside the event loop.
- callback
- Related: event binding, mainloop
A function passed to another component to be invoked later when something happens, such as a button press or a completed request. It should return quickly to avoid freezing the UI.
- widget
- Related: geometry manager, tkinter
A visible GUI component such as a button, label, entry, or frame. Widgets are arranged in a parent-child hierarchy and configured through options like text, width, and command.
- REST
- Related: HTTP method, idempotent request, status code
An architectural style for networked APIs using stateless requests, resource-oriented URLs, and standard HTTP methods. Representations are typically JSON, and servers should not rely on client session state.
- HTTP method
- Related: REST, idempotent request
The verb in a request indicating intent: GET retrieves, POST creates, PUT replaces, PATCH partially updates, and DELETE removes. Choosing the right method keeps APIs predictable.
- idempotent request
- Related: HTTP method, retry with backoff
A request that produces the same server state whether sent once or many times. GET, PUT, and DELETE are idempotent; POST usually is not, which matters for safe retries.
- status code
- Related: REST, raise_for_status
A three-digit number in an HTTP response summarizing the outcome, such as 200 success, 201 created, 404 not found, or 500 server error. Clients branch on these values.
- requests.Session
- Related: requests library, timeout
An object that persists settings across requests, including headers, cookies, and connection pooling. Reusing one session speeds up repeated calls to the same host.
- requests library
- Related: requests.Session, raise_for_status
A popular third-party HTTP client offering simple functions like get and post. Responses expose status_code, headers, text, and a json() method for parsing JSON bodies.
- raise_for_status
- Related: status code, requests library
A response method that raises an exception when the status code indicates a client or server error. It replaces manual status checks and surfaces failed calls immediately.
- timeout
- Related: requests.Session, retry with backoff
A limit on how long a client waits for a connection or response. Always setting it prevents a program from hanging indefinitely when a server stops responding.
- JSON
- Related: deserialization, REST
A lightweight text data format of objects, arrays, strings, numbers, booleans, and null. Python maps it to dicts, lists, and primitives via the json module.
- deserialization
- Related: JSON, authentication token
Converting a transferred representation such as JSON text into native objects. In Python, json.loads produces dicts and lists; the result should be validated before use.
- authentication token
- Related: requests.Session, JSON
A credential string sent with requests, typically in an Authorization header, proving the caller's identity. Bearer tokens should be stored securely and never committed to source control.
- pagination
- Related: query parameter, REST
Splitting a large result set into pages using query parameters like limit and offset or a cursor. Clients must follow links or cursors until no further records remain.
- query parameter
- Related: pagination, REST
A key-value pair appended to a URL after a question mark, used for filtering, sorting, or paging. The requests library accepts them as a params dictionary.
- retry with backoff
- Related: idempotent request, timeout
Resending a failed request after increasing delays, often with jitter, to handle transient errors. It should be limited to idempotent operations or those with safe retry semantics.