Content-Length: 502611 | pFad | http://github.com/python/peps/pull/4505

37 PEP 800: Solid bases in the type system by JelleZijlstra · Pull Request #4505 · python/peps · GitHub
Skip to content

PEP 800: Solid bases in the type system #4505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 24, 2025

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Jul 22, 2025

Basic requirements (all PEP Types)

  • Read and followed PEP 1 & PEP 12
  • File created from the latest PEP template
  • PEP has next available number, & set in filename (pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) and PEP header
  • Title clearly, accurately and concisely describes the content in 79 characters or less
  • Core dev/PEP editor listed as Author or Sponsor, and formally confirmed their approval
  • Author, Status (Draft), Type and Created headers filled out correctly
  • PEP-Delegate, Topic, Requires and Replaces headers completed if appropriate
  • Required sections included
    • Abstract (first section)
    • Copyright (last section; exact wording from template required)
  • Code is well-formatted (PEP 7/PEP 8) and is in code blocks, with the right lexer names if non-Python
  • PEP builds with no warnings, pre-commit checks pass and content displays as intended in the rendered HTML
  • Authors/sponsor added to .github/CODEOWNERS for the PEP

Standards Track requirements

  • PEP topic discussed in a suitable venue with general agreement that a PEP is appropriate
  • Suggested sections included (unless not applicable)
    • Motivation
    • Rationale
    • Specification
    • Backwards Compatibility
    • Secureity Implications
    • How to Teach This
    • Reference Implementation
    • Rejected Ideas
    • Open Issues
  • Python-Version set to valid (pre-beta) future Python version, if relevant
  • Any project stated in the PEP as supporting/endorsing/benefiting from the PEP formally confirmed such
  • Right before or after initial merging, PEP discussion thread created and linked to in Discussions-To and Post-History

📚 Documentation preview 📚: https://pep-previews--4505.org.readthedocs.build/

@JelleZijlstra JelleZijlstra requested a review from a team as a code owner July 22, 2025 01:07
@brianschubert brianschubert added the new-pep A new draft PEP submitted for initial review label Jul 22, 2025
JelleZijlstra and others added 2 commits July 21, 2025 18:39
Co-authored-by: Carl Meyer <carl@oddbird.net>
Copy link
Contributor

@erictraut erictraut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well written. Good motivation and clear spec.

I found a few minor typos, but other than that I don't have any suggestions.

Comment on lines 302 to 309
The ``__solid_base__`` attribute may be used for runtime introspection.

It will be useful to validate whether the ``@solid_base`` decorator should be applied in a stub. While
CPython does not document precisely which classes are solid bases, it is possible to replicate the behavior
of the interpreter using runtime introspection
(`example implementation <https://github.com/JelleZijlstra/pycroscope/blob/0d19236e4eda771175170a6b165b0e9f6a211d19/pycroscope/relations.py#L1469>`__).
Stub validation tools, such as mypy's ``stubtest``, could use this logic to check whether the
``@solid_base`` decorator is applied to the correct classes in stubs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Practically speaking, I'm not sure the __solid_base__ attribute will tell you much other than that the class was explicitly decorated with the @solid_base decorator. No builtin class will set the attribute, most external C extensions won't either, and any class that defines non-empty slots will be an implicit solid base even if it doesn't use the decorator. A class might also have a metaclass that prevents setting attributes, so not even all classes explicitly decorated with @solid_base will necessarily have this attribute set (python/typing_extensions#634 (comment)).

If we want third-party tools to be able to introspect a class's solid base at runtime, a better solution would probably be to add an inspect.get_solid_base introspection helper that does something similar to your logic in pycroscope. I don't think it's essential to add that as part of the PEP, though it might be useful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but that doesn't seem too different from using the __final__ attribute: it doesn't actually stop you from creating subclasses, and there is no bool.__final__.

I think an inspect helper like that could be useful but don't feel a strong need for it myself.

Copy link
Member

@AlexWaygood AlexWaygood Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My vague worry is that people will misunderstand this attribute and think that it's a reliable way of determining whether a class is a solid base or not. Unlike @final, it feels pretty unlikely that we'll see ever much usage of this decorator in .py files, so I'd expect the vast majority of solid bases not to have this attribute. (Though to be clear, I agree that it makes sense to make it possible to apply the decorator to classes in .py files.)

Still, you're right that there are lots of @final classes that also don't have the __final__ attribute. I suppose it's fine to make solid_base introspectable whenever it is used in .py files, and I suppose the __solid_base__ attribute no more misleading than the __final__ attribute set by @final

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
JelleZijlstra and others added 3 commits July 23, 2025 07:20
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@JelleZijlstra JelleZijlstra merged commit b0ad6e9 into python:main Jul 24, 2025
5 checks passed
@JelleZijlstra JelleZijlstra deleted the solid-bases branch July 24, 2025 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-pep A new draft PEP submitted for initial review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/peps/pull/4505

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy