Skip to content

Commit 66fdbc8

Browse files
committed
Minor fixes
1 parent f521723 commit 66fdbc8

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

docs/source/final_attrs.rst

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ neither of the above use cases can be solved with it.
4343
.. note::
4444

4545
This is an experimental feature. Some details might change in later
46-
versions of mypy. The final qualifiers are available in ``typing_extensions``
47-
module.
46+
versions of mypy. The final qualifiers are available in the
47+
``typing_extensions`` package available on PyPI.
4848

49-
Definition syntax
50-
*****************
49+
Syntax variants
50+
***************
5151

5252
The ``typing_extensions.Final`` qualifier indicates that a given name or
5353
attribute should never be re-assigned, re-defined, nor overridden. It can be
@@ -64,10 +64,10 @@ used in one of these forms:
6464
classes this is *not* the same as ``Final[Any]``. Here mypy will infer
6565
type ``int``.
6666

67-
* In stub files one can omit the right hand side and just write
67+
* In stub files you can omit the right hand side and just write
6868
``ID: Final[float]``.
6969

70-
* Finally, one can define ``self.id: Final = 1`` (also with a type argument),
70+
* Finally, you can define ``self.id: Final = 1`` (also with a type argument),
7171
but this is allowed *only* in ``__init__`` methods.
7272

7373
Definition rules
@@ -104,14 +104,15 @@ The are two rules that should be always followed when defining a final name:
104104
ID = 1
105105
ID: Final = 2 # Error!
106106
107-
* A final attribute declared in class body without r.h.s. must be initialized
108-
in the ``__init__`` method (one can skip initializer in stub files):
107+
* A final attribute declared in class body without an initializer must
108+
be initialized in the ``__init__`` method (you can skip the initializer
109+
in stub files):
109110

110111
.. code-block:: python
111112
112113
class SomeCls:
113-
x: Final
114-
y: Final # Error: final attribute without an initializer
114+
x: Final[int]
115+
y: Final[int] # Error: final attribute without an initializer
115116
def __init__(self) -> None:
116117
self.x = 1 # Good
117118

mypy/semanal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,8 +2049,8 @@ def analyze_lvalue(self, lval: Lvalue, nested: bool = False,
20492049
if final_cb is not None:
20502050
# We avoid extra errors if the original definition is also final
20512051
# by keeping the final status of this assignment.
2052-
keep_final = (original_def and isinstance(original_def.node, Var) and
2053-
original_def.node.is_final)
2052+
keep_final = bool(original_def and isinstance(original_def.node, Var) and
2053+
original_def.node.is_final)
20542054
final_cb(keep_final)
20552055
if explicit_type:
20562056
# Don't re-bind types
@@ -2100,7 +2100,7 @@ def analyze_tuple_or_list_lvalue(self, lval: TupleExpr,
21002100
explicit_type=explicit_type)
21012101

21022102
def analyze_member_lvalue(self, lval: MemberExpr, explicit_type: bool = False,
2103-
final_cb: Optional[Callable[[], None]] = None) -> None:
2103+
final_cb: Optional[Callable[[bool], None]] = None) -> None:
21042104
"""Analyze lvalue that is a member expression.
21052105
21062106
Arguments:

0 commit comments

Comments
 (0)