Skip to content

Commit 06ce4cc

Browse files
committed
Add example of @Final with @Property to the typing spec
I thought it would be nice to add an example showing the use of @Final and @Property together, but I also think the existing content is reasonably clear that this example is supposed to work.
1 parent 52aad76 commit 06ce4cc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: docs/spec/qualifiers.rst

+16
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ implementation (or on the first overload, for stubs)::
6666
def method(self, x=None):
6767
...
6868

69+
The ``@final`` decorator can be combined with previous decorators, like
70+
``@property``. Example::
71+
72+
from typing import final
73+
74+
class Base:
75+
@final
76+
@property
77+
def foo(self) -> None:
78+
...
79+
80+
class Derived(Base):
81+
@property
82+
def foo(self) -> None: # Error: Cannot override final attribute "foo"
83+
...
84+
6985
It is an error to use ``@final`` on a non-method function.
7086

7187
.. _`uppercase-final`:

0 commit comments

Comments
 (0)