https://github.com/izxxr/runtime-final
Declare final Python classes and methods at runtime.
https://github.com/izxxr/runtime-final
final final-classes python python-typing python3 runtime typing
Last synced: 29 days ago
JSON representation
Declare final Python classes and methods at runtime.
- Host: GitHub
- URL: https://github.com/izxxr/runtime-final
- Owner: izxxr
- License: mit
- Created: 2022-06-25T07:18:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-18T18:14:39.000Z (about 3 years ago)
- Last Synced: 2025-12-15T11:51:10.181Z (3 months ago)
- Topics: final, final-classes, python, python-typing, python3, runtime, typing
- Language: Python
- Homepage: https://runtime-final.readthedocs.io
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# runtime-final
Declare final Python classes and methods at runtime.
This module provides a decorator based interface to declare final
classes and methods. This module is inspired by and is compatible with [`typing.final`](https://docs.python.org/3/library/typing.html#typing.final).
See [PEP-591](https://www.python.org/dev/peps/pep-0591) for more
details on this topic.
## Installation
**Python 3.6 or higher is required.**
You can simply install this module from `pip`.
```
python -m pip install runtime-final
```
## Usage
The main component of this module is the `final` decorator that
can be used to decorate classes and methods inside a class. As
such:
- Classes decorated with @final cannot be subclassed.
- Methods decorated with @final cannot be overriden in subclasses.
For example with classes:
```py
from runtime_final import final
@final
class Foo:
...
class Bar(Foo): # Raises RuntimeError
...
```
And with methods:
```py
from runtime_final import final
class User:
@final
def edit(self):
...
class AnotherUser(User):
def edit(self): # Raises RuntimeError
...
```
## Documentation
For more details, see the [documentation](https://runtime-final.readthedocs.io)