Skip to content

moscow-python-beer/final-class

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

final_class

wemake.services test codecov Python Version wemake-python-styleguide

Final classes for python3.6+.

Features

  • No metaclass conflicts
  • No runtime overhead
  • No dependencies
  • Type hints included, PEP-561 and PEP-591 compatible
  • Designed to be as simple as possible

Why?

In languages like java we have a nice way to restrict subclassing any class by making it final:

public final class SomeClass {
  // ...
}

In python we don't have such feature out of the box. That's where final_class library comes in!

This package works perfectly with @final from typing. So, with final_class you will have both type-checking and runtime checks.

Installation

pip install final_class

Usage

from final_class import final


@final
class Example(object):  # You won't be able to subclass it!
    ...


class Error(Example):  # Raises `TypeError`
    ...

More?

Do you want more? Check out:

License

MIT.