NET Core, Perl, PHP, PL/SQL, Python, Ruby, T-SQL, Swift, Visual Basic 6. I'm not familiar enough with pyright to know if it has a different preferred way of suppressing errors. Source Code Analysis Tools on the main website for The OWASP Foundation. 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. It leverages all of VS Code's power to provide auto complete and IntelliSense, linting, debugging, and unit testing, along with the ability to easily switch between Python environments, including virtual and conda environments. The extension makes VS Code an excellent Python editor, and works on any operating system with a variety of Python interpreters. ![]() ![]() There is perhaps a principled reason why pyright is deciding to do this that I'm overlooking, but IMO this seems like a bug. Working with Python in Visual Studio Code, using the Microsoft Python extension, is simple, fun, and productive. What pyright seems to do instead is to just "leak" the generic variable. Report an error and ask the user to specify the desired generic type.Some type checkers may attempt to do this, but I don't know of any that handles this particular case perfectly. Attempt to infer the correct type based on context.This is what pyre and pytype does - they deduce 'tmpfolder' has type 'Any' and 'nothing' respectively. Both types are a valid subtype of every type, so are guaranteed to be valid placeholders and not cause downstream errors. Pick some placeholder type like either 'Any', the dynamic type, or NoReturn (aka 'bottom' aka 'nothing').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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |