From 414dce170e63694478fb07e7cfefe74e96bf6838 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Tue, 7 Mar 2023 10:16:14 -0700 Subject: [PATCH] Updated documentation for import modeling differences between mypy and pyright. --- docs/mypy-comparison.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/mypy-comparison.md b/docs/mypy-comparison.md index 2c32971e5..3c5e27d5d 100644 --- a/docs/mypy-comparison.md +++ b/docs/mypy-comparison.md @@ -355,11 +355,16 @@ Overload resolution rules are under-specified in PEP 484. Pyright and mypy apply Pyright intentionally does not model implicit side effects of the Python import loading mechanism. In general, such side effects cannot be modeled statically because they depend on execution order. Dependency on such side effects leads to fragile code, so pyright treats these as errors. For more details, refer to [this documentation](import-statements.md). -Mypy models some side effects of the import loader. If an import statement imports a submodule using a multi-part module reference, mypy assumes that all of the parent modules are also initialized and cached such they can be referenced. +Mypy models side effects of the import loader that are potentially unsafe. ```python -import collections.abc -collections.deque() # Pyright produces an error here because the `collections` module wasn't explicitly imported +import http + +def func(): + import http.cookies + +# The next line raises an exception at runtime +x = http.cookies # mypy allows, pyright flags as error ``` ### Ellipsis in Function Body