Skip to content

Commit c282ac8

Browse files
let extra-checks example compile
This would raise a name-defined error. I fixed it and elaborated/rephrased a little.
1 parent 69112dd commit c282ac8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

docs/source/command_line.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,8 @@ of the above sections.
775775
.. option:: --extra-checks
776776

777777
This flag enables additional checks that are technically correct but may be
778-
impractical. In particular, it prohibits partial overlap in ``TypedDict`` updates,
779-
and makes arguments prepended via ``Concatenate`` positional-only. For example:
778+
impractical. In particular, it prohibits partial overlap in ``TypedDict`` updates.
779+
For example:
780780

781781
.. code-block:: python
782782
@@ -790,14 +790,20 @@ of the above sections.
790790
b: int
791791
792792
def test(foo: Foo, bar: Bar) -> None:
793-
# This is technically unsafe since foo can have a subtype of Foo at
794-
# runtime, where type of key "b" is incompatible with int, see below
795-
bar.update(foo)
793+
# This is unsafe since foo can have a subtype of Foo at
794+
# runtime, where type of key "b" is incompatible with int.
795+
# See the usage below for an example of that unsafe situation.
796+
bar.update(foo) # error: Argument 1 to "update" of "TypedDict" has incompatible type "Foo"; expected "TypedDict({'a': int, 'b'?: int})" [typeddict-item]
796797
797798
class Bad(Foo):
798799
b: str
799800
bad: Bad = {"a": 0, "b": "no"}
800-
test(bad, bar)
801+
innocent_bar: Bar = Bar(a=1, b=1)
802+
print(innocent_bar) # {'a': 1, 'b': 1}; types are correct, all is good.
803+
test(bad, innocent_bar)
804+
print(innocent_bar) # {'a': 0, 'b': 'no'}; types are now incorrect, uh oh.
805+
806+
It also makes arguments prepended via ``Concatenate`` positional-only.
801807

802808
In future more checks may be added to this flag if:
803809

0 commit comments

Comments
 (0)