https://github.com/moscow-python-beer/final-class
🔒 Final classes for Python3!
https://github.com/moscow-python-beer/final-class
final-classes oop oop-principles python python3 python36
Last synced: 20 days ago
JSON representation
🔒 Final classes for Python3!
- Host: GitHub
- URL: https://github.com/moscow-python-beer/final-class
- Owner: moscow-python-beer
- License: mit
- Created: 2018-07-11T09:17:25.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-07-21T07:41:26.000Z (almost 5 years ago)
- Last Synced: 2025-12-15T16:54:19.996Z (4 months ago)
- Topics: final-classes, oop, oop-principles, python, python3, python36
- Language: Python
- Homepage: https://pypi.org/project/final-class/
- Size: 813 KB
- Stars: 17
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# final_class
[](https://wemake.services)
[](https://github.com/moscow-python-beer/final-class/actions?query=workflow%3Atest)
[](https://codecov.io/gh/moscow-python-beer/final-class)
[](https://pypi.org/project/final-class/)
[](https://github.com/wemake-services/wemake-python-styleguide)
Final classes for `python3.6+`.
## Features
- No metaclass conflicts
- No runtime overhead
- No dependencies
- Type hints included, [PEP-561](https://www.python.org/dev/peps/pep-0561/) and [PEP-591](https://www.python.org/dev/peps/pep-0591/) 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`:
```java
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
```bash
pip install final_class
```
## Usage
```python
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:
- [1-minute guide to real constants in Python](https://sobolevn.me/2018/07/real-python-contants)
## License
MIT.