Content · Programming · Python

Python Disjoint Type Bases: What Type Checkers Can Infer

Explain how disjoint base classes let type checkers rule out impossible overlaps.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

Explain how disjoint base classes let type checkers rule out impossible overlaps.

What It Does and Why It Matters


@typing.disjoint_base marks a nominal class as a base that cannot be combined with unrelated disjoint bases according to static typing rules. This helps type checkers reason about impossible isinstance combinations and multiple inheritance. The decoration communicates typing intent; it does not add a runtime value validator.

Added in Python 3.15. Multiple inheritance conflicts are primarily analyzed by type checkers; implementation rules may also reject some combinations.

Version requirement: this example needs Python 3.15 or newer. @disjoint_base communicates typing constraints; runtime inheritance rules and static checks are distinct.

Step-by-Step Example


Start with the complete example below. Read the inputs and predict what the final print statement will show before you run it.

from typing import disjoint_base
@disjoint_base
class Invoice:
    pass
@disjoint_base
class Shipment:
    pass
item = Invoice()
print(isinstance(item, Invoice))
print(isinstance(item, Shipment))

How the Code Works


  • The imports make these standard-library tools available: typing.
  • The definition of Invoice, Shipment creates reusable behavior; its body runs only when called or instantiated as appropriate.
  • The name item receives the value of Invoice(). Changing this input lets you explore a different case.
  • The print calls display the results. Compare these results with the method’s documented return type and the input used.
  • Decorated classes remain ordinary classes at runtime. Type checkers use their disjoint-base status when reasoning about inheritance and overlaps.

This example requires a newer interpreter than the local verification environment. Run it in a compatible Python installation and compare with the documented behavior.

What to Notice


Pay attention to the accepted input types, the returned value and the boundary behavior. Predict what changes if you replace the example input with an empty, zero, negative or missing value, where that value is meaningful for this operation.

If the task uses a library function, inspect its documented exceptions and return type before reusing it inside a larger function.

Where You Would Use This


This helps maintain larger projects where functions and data shapes cross module boundaries. Check the code with a static analyzer, and still validate data received from files, users or remote APIs. Annotation constructs do not normally enforce types automatically at runtime.

Practice Exercise


Write two disjoint decorated bases, then inspect what a type checker reports for a class inheriting from both.

Before running your edited example, write down the result you expect. Then test at least one valid boundary or deliberately invalid value, using appropriate exception handling where necessary.

Reference: official Python documentation for the complete API contract and version notes.

Common Beginner Mistakes


  • Believing @disjoint_base automatically makes all logical constraints hold at runtime.
  • Overlooking the documented condition: @typing.disjoint_base marks a nominal class as a base that cannot be combined with unrelated disjoint bases according to static typing rules.

Key Takeaways


  • Explain how disjoint base classes let type checkers rule out impossible overlaps.
  • @typing.disjoint_base marks a nominal class as a base that cannot be combined with unrelated disjoint bases according to static typing rules.
  • Write two disjoint decorated bases, then inspect what a type checker reports for a class inheriting from both.
  • Version requirement: this example needs Python 3.15 or newer. @disjoint_base communicates typing constraints; runtime inheritance rules and static checks are distinct.
Share this resourceSend this page to someone who may find it useful.