| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| [file b.py] | ||
| import a | ||
| def g() -> int: | ||
| return a.y |
There was a problem hiding this comment.
Reveal the type of a.y (to verify that it doesn't somehow fall back to Any).
Sorry, something went wrong.
| [file a.py] | ||
| import b | ||
| def f() -> int: | ||
| return b.x |
There was a problem hiding this comment.
Reveal the type of b.x.
Sorry, something went wrong.
| in options.strict_optional_whitelist) | ||
|
|
||
| def check_first_pass(self) -> None: | ||
| """Type check the entire file, but defer functions with forward references.""" |
There was a problem hiding this comment.
Be more explicit about forward reference mean. In particular, they mean references to definitions whose types haven't been inferred yet.
Sorry, something went wrong.
|
Looks good to me! This hopefully fixes one of the biggest pain points mypy users with large code bases have had. I'd like to see some more test cases before merging:
def f() -> None:
a = b.x # Type of b.x only available during second pass
a + 1 # Error that we can't report during first pass
|
Sorry, something went wrong.
|
I'll add more tests. I also discovered that reveal_type() needs to check for current_node_deferred. |
Sorry, something went wrong.
|
Rebased, generalized the multi-pass machinery, and added a test that would require 3 passes. Still needs tests for (2) and (3). Also, there are still some print() calls left. |
Sorry, something went wrong.
|
I could use a hint for (2). |
Sorry, something went wrong.
|
I think I have all the required tests now. Jukka, can you double-check? |
Sorry, something went wrong.
Current coverage is 84.90% (diff: 100%)@@ master #2264 diff @@
==========================================
Files 72 72
Lines 19037 20953 +1916
Methods 0 0
Messages 0 0
Branches 3919 4824 +905
==========================================
+ Hits 15819 17790 +1971
+ Misses 2618 2588 -30
+ Partials 600 575 -25
|
Sorry, something went wrong.
| return False | ||
| self.errors.set_file(self.path) | ||
| self.pass_num += 1 | ||
| print('---', self.path, 'pass', self.pass_num + 1, '---') |
There was a problem hiding this comment.
Remove print.
Sorry, something went wrong.
| for node, type_name in todo: | ||
| if node in done: | ||
| continue | ||
| print(type_name, '.', node.fullname() or node.name()) |
There was a problem hiding this comment.
Remove another print.
Sorry, something went wrong.
| tmp/a.py:4: error: Cannot determine type of 'x2' | ||
|
|
||
| [case testErrorInPassTwo] | ||
| # flags: --hide-error-context |
There was a problem hiding this comment.
Don't hide error context to test the it works correctly for errors reported in the second pass.
Sorry, something went wrong.
| import a | ||
| x = 1 + 1 | ||
| [out] | ||
| tmp/a.py:4: error: Unsupported operand types for + ("int" and "str") |
There was a problem hiding this comment.
Maybe also test this the other way as well (error reported in b.py in addition a.py).
Sorry, something went wrong.
| [file b.py] | ||
| from typing import Any | ||
| import a | ||
| def deco(f: Any) -> Any: |
There was a problem hiding this comment.
This decorator probably doesn't trigger a second pass, since simple decorator signatures are special cased in semantic analysis. A more complex decorator signature such as Callable[[T], int] -> Callable[[T]], str] is needed.
Sorry, something went wrong.
| [file a.py] | ||
| import b | ||
| def g() -> None: | ||
| f() |
There was a problem hiding this comment.
Make sure that the decorator function returns an interesting type (not Any) and do reveal_type(f()) here to verify that decorator got applied correctly.
Sorry, something went wrong.
These verify that deferral due to a cross-module dependency works.
|
Ready for review/merge. |
Sorry, something went wrong.
|
LGTM now -- thanks for the updates! |
Sorry, something went wrong.
|
OK, rebased and made all requested amendments.
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Might fix #481.