Skip to content

Commit c2876bf

Browse files
authored
[1.0 backport] [used before def] add documentation (#14592) (#14597)
Adding documentation for used-before-def check.
1 parent 8ef98cc commit c2876bf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/source/error_code_list.rst

+17
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ This example accidentally calls ``sort()`` instead of :py:func:`sorted`:
8989
9090
x = sort([3, 2, 4]) # Error: Name "sort" is not defined [name-defined]
9191
92+
93+
Check that a variable is not used before it's defined [used-before-def]
94+
-----------------------------------------------------------------------
95+
96+
Mypy will generate an error if a name is used before it's defined.
97+
While the name-defined check will catch issues with names that are undefined,
98+
it will not flag if a variable is used and then defined later in the scope.
99+
used-before-def check will catch such cases.
100+
101+
Example:
102+
103+
.. code-block:: python
104+
105+
print(x) # Error: Name "x" is used before definition [used-before-def]
106+
x = 123
107+
108+
92109
Check arguments in calls [call-arg]
93110
-----------------------------------
94111

0 commit comments

Comments
 (0)