Pyright: Any possibility to add more type checking?

Created on 17 Jul 2019  路  3Comments  路  Source: microsoft/pyright

Python 3.7.4

from typing import List, Union

As I expected, did not provide any error

stuff: List[Union[int, str, bool]] = ["Surush", "Mary", "Table",
True, False, "Sam",
99, 20, "TV", "Radio"]
print(stuff)

I like to see error for not providing bool in Union

stuff: List[Union[int, str]] = ["Surush", "Mary", "Table",
True, False, "Sam",
99, 20, "TV", "Radio"]
print(stuff)

I like to see error for not providing Union, str, and bool

stuff: List[int] = ["Surush", "Mary", "Table",
True, False, "Sam",
99, 20, "TV", "Radio"]
print(stuff)

enhancement request

Most helpful comment

For a full list of available configuration options, refer to this documentation page.

All 3 comments

Pyright supports various configuration settings that control the strictness level of type checking. It defaults to less strictness. For the above case, you can enable "strictListInference" to flag this error.

You can also enable "strict" mode, which enables all strict checks. This can be done on a per-file basis (by adding the comment " # pyright: strict" to the top of the file) or for entire subdirectories (by adding an array of directories to a "strict" section in the configuration file).

For a full list of available configuration options, refer to this documentation page.

Fantastic, thank you for the education Eric:). Sorry for the spam. Did as you described and looking great now:)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tamuhey picture tamuhey  路  3Comments

BjMrq picture BjMrq  路  3Comments

tamuhey picture tamuhey  路  3Comments

christopher-hesse picture christopher-hesse  路  3Comments

giyyapan picture giyyapan  路  3Comments