PEP 591: Discuss (not doing) runtime final enforcement (#1044)
Co-Authored-By: Ivan Levkivskyi <levkivskyi@gmail.com>
This commit is contained in:
parent
1e8f07b877
commit
b3c3e9bca4
11
pep-0591.rst
11
pep-0591.rst
|
@ -262,6 +262,17 @@ defined in the same module. Sealed classes seem most useful in
|
|||
combination with pattern matching, so it does not seem to justify the
|
||||
complexity in our case. This could be revisisted in the future.
|
||||
|
||||
It would be possible to have the ``@final`` decorator on classes
|
||||
dynamically prevent subclassing at runtime. Nothing else in ``typing``
|
||||
does any runtime enforcement, though, so ``final`` will not either.
|
||||
A workaround for when both runtime enforcement and static checking is
|
||||
desired is to use this idiom (possibly in a support module)::
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from typing import final
|
||||
else:
|
||||
from runtime_final import final
|
||||
|
||||
|
||||
References
|
||||
==========
|
||||
|
|
Loading…
Reference in New Issue