Skip to content

Commit 8c61a64

Browse files
update documentation
1 parent 2a8a8e2 commit 8c61a64

File tree

1 file changed

+66
-65
lines changed

1 file changed

+66
-65
lines changed

docs/source/command_line.rst

Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ for full details, see :ref:`running-mypy`.
8585

8686
This flag will add everything that matches ``.gitignore`` file(s) to :option:`--exclude`.
8787

88+
.. _optional-arguments:
8889

89-
Optional arguments
90+
Utility arguments
9091
******************
9192

9293
.. option:: -h, --help
@@ -1035,6 +1036,70 @@ in developing or debugging mypy internals.
10351036
cause mypy to type check the contents of ``temp.py`` instead of ``original.py``,
10361037
but error messages will still reference ``original.py``.
10371038

1039+
.. _enabling-incomplete-experimental-features:
1040+
1041+
Experimental features
1042+
*****************************************
1043+
1044+
.. option:: --enable-incomplete-feature {PreciseTupleTypes, InlineTypedDict}
1045+
1046+
Some features may require several mypy releases to implement, for example
1047+
due to their complexity, potential for backwards incompatibility, or
1048+
ambiguous semantics that would benefit from feedback from the community.
1049+
You can enable such features for early preview using this flag. Note that
1050+
it is not guaranteed that all features will be ultimately enabled by
1051+
default. In *rare cases* we may decide to not go ahead with certain
1052+
features.
1053+
1054+
List of currently incomplete/experimental features:
1055+
1056+
* ``PreciseTupleTypes``: this feature will infer more precise tuple types in
1057+
various scenarios. Before variadic types were added to the Python type system
1058+
by :pep:`646`, it was impossible to express a type like "a tuple with
1059+
at least two integers". The best type available was ``tuple[int, ...]``.
1060+
Therefore, mypy applied very lenient checking for variable-length tuples.
1061+
Now this type can be expressed as ``tuple[int, int, *tuple[int, ...]]``.
1062+
For such more precise types (when explicitly *defined* by a user) mypy,
1063+
for example, warns about unsafe index access, and generally handles them
1064+
in a type-safe manner. However, to avoid problems in existing code, mypy
1065+
does not *infer* these precise types when it technically can. Here are
1066+
notable examples where ``PreciseTupleTypes`` infers more precise types:
1067+
1068+
.. code-block:: python
1069+
1070+
numbers: tuple[int, ...]
1071+
1072+
more_numbers = (1, *numbers, 1)
1073+
reveal_type(more_numbers)
1074+
# Without PreciseTupleTypes: tuple[int, ...]
1075+
# With PreciseTupleTypes: tuple[int, *tuple[int, ...], int]
1076+
1077+
other_numbers = (1, 1) + numbers
1078+
reveal_type(other_numbers)
1079+
# Without PreciseTupleTypes: tuple[int, ...]
1080+
# With PreciseTupleTypes: tuple[int, int, *tuple[int, ...]]
1081+
1082+
if len(numbers) > 2:
1083+
reveal_type(numbers)
1084+
# Without PreciseTupleTypes: tuple[int, ...]
1085+
# With PreciseTupleTypes: tuple[int, int, int, *tuple[int, ...]]
1086+
else:
1087+
reveal_type(numbers)
1088+
# Without PreciseTupleTypes: tuple[int, ...]
1089+
# With PreciseTupleTypes: tuple[()] | tuple[int] | tuple[int, int]
1090+
1091+
* ``InlineTypedDict``: this feature enables non-standard syntax for inline
1092+
:ref:`TypedDicts <typeddict>`, for example:
1093+
1094+
.. code-block:: python
1095+
1096+
def test_values() -> {"int": int, "str": str}:
1097+
return {"int": 42, "str": "test"}
1098+
1099+
.. option:: --find-occurrences CLASS.MEMBER
1100+
1101+
This flag will make mypy print out all usages of a class member
1102+
based on static type information. This feature is experimental.
10381103

10391104
Report generation
10401105
*****************
@@ -1096,65 +1161,6 @@ format into the specified directory.
10961161
``mypy[reports]``.
10971162

10981163

1099-
Enabling incomplete/experimental features
1100-
*****************************************
1101-
1102-
.. option:: --enable-incomplete-feature {PreciseTupleTypes, InlineTypedDict}
1103-
1104-
Some features may require several mypy releases to implement, for example
1105-
due to their complexity, potential for backwards incompatibility, or
1106-
ambiguous semantics that would benefit from feedback from the community.
1107-
You can enable such features for early preview using this flag. Note that
1108-
it is not guaranteed that all features will be ultimately enabled by
1109-
default. In *rare cases* we may decide to not go ahead with certain
1110-
features.
1111-
1112-
List of currently incomplete/experimental features:
1113-
1114-
* ``PreciseTupleTypes``: this feature will infer more precise tuple types in
1115-
various scenarios. Before variadic types were added to the Python type system
1116-
by :pep:`646`, it was impossible to express a type like "a tuple with
1117-
at least two integers". The best type available was ``tuple[int, ...]``.
1118-
Therefore, mypy applied very lenient checking for variable-length tuples.
1119-
Now this type can be expressed as ``tuple[int, int, *tuple[int, ...]]``.
1120-
For such more precise types (when explicitly *defined* by a user) mypy,
1121-
for example, warns about unsafe index access, and generally handles them
1122-
in a type-safe manner. However, to avoid problems in existing code, mypy
1123-
does not *infer* these precise types when it technically can. Here are
1124-
notable examples where ``PreciseTupleTypes`` infers more precise types:
1125-
1126-
.. code-block:: python
1127-
1128-
numbers: tuple[int, ...]
1129-
1130-
more_numbers = (1, *numbers, 1)
1131-
reveal_type(more_numbers)
1132-
# Without PreciseTupleTypes: tuple[int, ...]
1133-
# With PreciseTupleTypes: tuple[int, *tuple[int, ...], int]
1134-
1135-
other_numbers = (1, 1) + numbers
1136-
reveal_type(other_numbers)
1137-
# Without PreciseTupleTypes: tuple[int, ...]
1138-
# With PreciseTupleTypes: tuple[int, int, *tuple[int, ...]]
1139-
1140-
if len(numbers) > 2:
1141-
reveal_type(numbers)
1142-
# Without PreciseTupleTypes: tuple[int, ...]
1143-
# With PreciseTupleTypes: tuple[int, int, int, *tuple[int, ...]]
1144-
else:
1145-
reveal_type(numbers)
1146-
# Without PreciseTupleTypes: tuple[int, ...]
1147-
# With PreciseTupleTypes: tuple[()] | tuple[int] | tuple[int, int]
1148-
1149-
* ``InlineTypedDict``: this feature enables non-standard syntax for inline
1150-
:ref:`TypedDicts <typeddict>`, for example:
1151-
1152-
.. code-block:: python
1153-
1154-
def test_values() -> {"int": int, "str": str}:
1155-
return {"int": 42, "str": "test"}
1156-
1157-
11581164
Miscellaneous
11591165
*************
11601166

@@ -1201,11 +1207,6 @@ Miscellaneous
12011207
type checking results. This can make it easier to integrate mypy
12021208
with continuous integration (CI) tools.
12031209

1204-
.. option:: --find-occurrences CLASS.MEMBER
1205-
1206-
This flag will make mypy print out all usages of a class member
1207-
based on static type information. This feature is experimental.
1208-
12091210
.. option:: --scripts-are-modules
12101211

12111212
This flag will give command line arguments that appear to be

0 commit comments

Comments
 (0)