
If you don't see the Python web project templates, select Tools > Get Tools and Features to run the Visual Studio Installer. Choose Web Project from the list, and then select Next: In the Create a new project dialog box, enter "Python web" in the search field at the top. I'm not familiar enough with pyright to know if it has a different preferred way of suppressing errors.On the start screen, select Create a new project. To answer your other questions, your example program is idiomatic Python, and type checkers should ideally support it without modification.Īdding a # type: ignore comment to the line with the error is the PEP 484 sanctioned way of suppressing error messages. There is perhaps a principled reason why pyright is deciding to do this that I'm overlooking, but IMO this seems like a bug. What pyright seems to do instead is to just "leak" the generic variable.

For example, mypy ends up picking 'str' by default, giving 'tmpfolder' a type of 'str'.

Pick some default generic type based on the typevar, such as 'str' or 'Union'.In this case, I think there are several reasonable things for a type checker to do: However, your example code omits specifying the generic type, leaving it up to the type checker to infer something appropriate. In short, the tempfile.TemporaryDirectory class is typed to be generic with respect to AnyStr.
