Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7794659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:50:22+00:00 2026-06-01T22:50:22+00:00

Is there any rule about which built-in and standard library classes are not subclassable

  • 0

Is there any rule about which built-in and standard library classes are not subclassable (“final”)?

As of Python 3.3, here are a few examples:

  • bool
  • function
  • operator.itemgetter
  • slice

I found a question which deals with the implementation of “final” classes, both in C and pure Python.

I would like to understand what reasons may explain why a class is chosen to be “final” in the first place.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:50:24+00:00Added an answer on June 1, 2026 at 10:50 pm

    There seems to be two reasons for a class to be “final” in Python.

    1. Violation of Class Invariant

    Classes that follow Singleton pattern have an invariant that there’s a limited (pre-determined) number of instances. Any violation of this invariant in a subclass will be inconsistent with the class’ intent, and would not work correctly. Examples:

    • bool: True, False; see Guido’s comments
    • NoneType: None
    • NotImplementedType: NotImplemented
    • ellipsis: Ellipsis

    There may be cases other than the Singleton pattern in this category but I’m not aware of any.

    2. No Persuasive Use Case

    A class implemented in C requires additional work to allow subclassing (at least in CPython). Doing such work without a convincing use case is not very attractive, so volunteers are less likely to come forward. Examples:

    • function; see Tim Peters’ post

    Note 1:

    I originally thought there were valid use cases, but simply insufficient interest, in subclassing of function and operator.itemgetter. Thanks to @agf for pointing out that the use cases offered here and here are not convincing (see @agf comments to the question).

    Note 2:

    My concern is that another Python implementation might accidentally allow subclassing a class that’s final in CPython. This may result in non-portable code (a use case may be weak, but someone might still write code that subclasses function if their Python supports it). This can be resolved by marking in Python documentation all built-in and standard library classes that cannot be subclassed, and requiring that all implementations follow CPython behavior in that respect.

    Note 3:

    The message produced by CPython in all the above cases is:

    TypeError: type 'bool' is not an acceptable base type
    

    It is quite cryptic, as numerous questions on this subject show. I’ll submit a suggestion to add a paragraph to the documentation that explains final classes, and maybe even change the error message to:

    TypeError: type 'bool' is final (non-extensible)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm confused about which to use and when. Is there a rule of thumb?
Is there any way (apart form actual perfomance measurements which can be pretty hard
Is there any way to change the BackColor of the border of a panel
Is there any native compression (for javascript/css files) available in ASP.NET?
Are there any open-source compression/decomp libraries available for Ruby? Has anyone implemented LZW? Or,
Is there any way I can run class files (i.e. with main as the
Is there any way to view the reduction steps in haskell, i.e trace the
Is there any advantage of using int vs varbinary for storing bit masks in
Is there any real difference to screen reader users (or any users really) whether
Is there any way to change the icon of an application after it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.