Skip to content

PEP 800: Disjoint bases #14444

Closed
Closed

Description

@JelleZijlstra

I just posted https://peps.python.org/pep-0800/, which proposes adding an @solid_base decorator to the type system. "Solid bases" are classes that don't allow inheritance from other solid bases, which includes most builtins.

Usually our policy is not to use draft PEPs in typeshed until they are accepted. I think in this case, it's worth making an exception:

  • Even if type checkers don't support the decorator, they'll still be able to use the stubs with no regression in functionality. They'll just see an identity decorator on some classes. I tried this just now in Add @typing_extensions.solid_base #14443 and CI shows that mypy and pyright are unaffected by the presence of the decorator on int and str. (There are some other CI failures for unrelated reasons.)
  • While type checkers could implement the feature before typeshed adds @solid_base decorators, the feature will be a lot more useful if standard library classes are correctly marked with the decorator.

If we're in agreement, I would propose to start adding the decorator in typeshed once there is a typing_extensions release with the new feature. I can then also add stubtest support for checking whether the decorator should be present.

Activity

  1. JelleZijlstra commented on Aug 18, 2025

    @JelleZijlstra
    MemberAuthor

    I implemented stubtest support (python/mypy#19678). These are the classes that should be marked as disjoint bases (new name for solid bases) in 3.13:

    _ast.AST
    _asyncio.Future
    _asyncio.Task
    _collections_abc.MappingView
    _csv.Dialect
    _csv.Reader
    _csv.Writer
    _decimal.Context
    _decimal.Decimal
    _hashlib.HASH
    _interpreters.CrossInterpreterBufferView
    _io.BufferedRWPair
    _io.BufferedRandom
    _io.BufferedReader
    _io.BufferedWriter
    _io.BytesIO
    _io.FileIO
    _io.IncrementalNewlineDecoder
    _io.StringIO
    _io.TextIOWrapper
    _io._IOBase
    _lsprof.Profiler
    _multibytecodec.MultibyteIncrementalDecoder
    _multibytecodec.MultibyteIncrementalEncoder
    _multibytecodec.MultibyteStreamReader
    _multibytecodec.MultibyteStreamWriter
    _pickle.Pickler
    _pickle.Unpickler
    _queue.SimpleQueue
    _random.Random
    _socket.socket
    _sqlite3.Connection
    _sqlite3.Cursor
    _sqlite3.Row
    _ssl._SSLContext
    _struct.Struct
    _thread._local
    _threading_local._localimpl
    _threading_local.local
    _weakref.ReferenceType
    array.array
    ast.AST
    asyncio.BaseTransport
    asyncio.Future
    asyncio.Handle
    asyncio.Task
    asyncio.TimerHandle
    asyncio.events.Handle
    asyncio.events.TimerHandle
    asyncio.futures.Future
    asyncio.tasks.Task
    asyncio.transports.BaseTransport
    asyncio.transports._FlowControlMixin
    asyncio.trsock.TransportSocket
    builtins.AttributeError
    builtins.BaseException
    builtins.BaseExceptionGroup
    builtins.ImportError
    builtins.NameError
    builtins.OSError
    builtins.StopIteration
    builtins.SyntaxError
    builtins.SystemExit
    builtins.UnicodeDecodeError
    builtins.UnicodeEncodeError
    builtins.UnicodeTranslateError
    builtins.bytearray
    builtins.bytes
    builtins.classmethod
    builtins.complex
    builtins.dict
    builtins.enumerate
    builtins.filter
    builtins.float
    builtins.frozenset
    builtins.int
    builtins.list
    builtins.map
    builtins.object
    builtins.property
    builtins.reversed
    builtins.set
    builtins.staticmethod
    builtins.str
    builtins.super
    builtins.tuple
    builtins.type
    builtins.zip
    collections.OrderedDict
    collections.defaultdict
    collections.deque
    dataclasses.Field
    dataclasses.InitVar
    datetime.date
    datetime.datetime
    datetime.time
    datetime.timedelta
    decimal.Context
    decimal.Decimal
    fractions.Fraction
    functools.partial
    hmac.HMAC
    inspect.BoundArguments
    inspect.Parameter
    inspect.Signature
    io.BufferedRWPair
    io.BufferedRandom
    io.BufferedReader
    io.BufferedWriter
    io.BytesIO
    io.FileIO
    io.IncrementalNewlineDecoder
    io.StringIO
    io.TextIOWrapper
    ipaddress.IPv4Address
    ipaddress.IPv6Address
    itertools.accumulate
    itertools.batched
    itertools.chain
    itertools.combinations
    itertools.combinations_with_replacement
    itertools.compress
    itertools.count
    itertools.cycle
    itertools.dropwhile
    itertools.filterfalse
    itertools.groupby
    itertools.islice
    itertools.pairwise
    itertools.permutations
    itertools.product
    itertools.repeat
    itertools.starmap
    itertools.takewhile
    itertools.zip_longest
    mmap.mmap
    multiprocessing.managers.Token
    pathlib.PurePath
    pickle.Pickler
    pickle.Unpickler
    pickletools.ArgumentDescriptor
    pickletools.OpcodeInfo
    pickletools.StackObject
    queue.SimpleQueue
    socket.socket
    sqlite3.Connection
    sqlite3.Cursor
    sqlite3.Row
    sqlite3.dbapi2.Connection
    sqlite3.dbapi2.Cursor
    sqlite3.dbapi2.Row
    statistics.NormalDist
    struct.Struct
    tarfile.TarInfo
    traceback.FrameSummary
    tracemalloc.Frame
    tracemalloc.Statistic
    tracemalloc.StatisticDiff
    tracemalloc.Trace
    tracemalloc.Traceback
    types.GenericAlias
    types.ModuleType
    types.SimpleNamespace
    uuid.UUID
    weakref.KeyedRef
    weakref.ReferenceType
    weakref.WeakMethod
    xml.dom.expatbuilder.ElementInfo
    xml.dom.expatbuilder.FilterCrutch
    xml.dom.expatbuilder.FilterVisibilityController
    xml.dom.minidom.Attr
    xml.dom.minidom.CharacterData
    xml.dom.minidom.Document
    xml.dom.minidom.Element
    xml.dom.minidom.ElementInfo
    xml.dom.minidom.Identified
    xml.dom.minidom.NamedNodeMap
    xml.dom.minidom.ProcessingInstruction
    xml.dom.minidom.ReadOnlySequentialNamedNodeMap
    xml.dom.minidom.TypeInfo
    xml.dom.xmlbuilder.DOMEntityResolver
    xml.dom.xmlbuilder.DOMInputSource
    xml.etree.ElementTree.Element
    xml.etree.ElementTree.TreeBuilder
    xml.etree.ElementTree.XMLParser
    xml.etree.cElementTree.Element
    xml.etree.cElementTree.TreeBuilder
    xml.etree.cElementTree.XMLParser
    zipfile.ZipInfo
    zoneinfo.ZoneInfo
    

    In earlier versions the list is a little different; before Python 3.12, classes that inherit directly from classes implemented in C are generally disjoint bases. This most commonly affects namedtuples.

  2. changed the title [-]PEP 800: Solid bases[/-] [+]PEP 800: Disjoint bases[/+] on Aug 18, 2025
  3. brianschubert commented on Mar 25, 2026

    @brianschubert
    Collaborator

    @disjoint_base has now been added to the stubs (e.g. in #14599, #14683, #14716). Anything else needed here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    project: feature trackerTracks whether a typing feature can be used in typeshed stubs

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions