PEP 591: Discuss (not doing) runtime final enforcement (#1044)

Co-Authored-By: Ivan Levkivskyi <levkivskyi@gmail.com>
This commit is contained in:
Michael J. Sullivan 2019-05-10 18:40:46 -07:00 committed by Guido van Rossum
parent 1e8f07b877
commit b3c3e9bca4
1 changed files with 11 additions and 0 deletions

View File

@ -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
==========