8000 Fine-grained: Don't infer partial types from multiple targets by JukkaL · Pull Request #4553 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Fine-grained: Don't infer partial types from multiple targets #4553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 20, 2018
Prev Previous commit
Next Next commit
Set local_partial_types correctly
  • Loading branch information
JukkaL committed Feb 8, 2018
commit 9059894a3debf95173c5a78f4cf5e21bc15490a7
4 changes: 4 additions & 0 deletions mypy/dmypy_server.py < 8000 svg style="display: none;" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-check color-fg-success">
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def __init__(self, flags: List[str]) -> None:
options.cache_fine_grained = True # set this so that cache options match
else:
options.cache_dir = os.devnull
options.cache_dir = os.devnull
# Fine-grained incremental doesn't support general partial types
# (details in https://github.com/python/mypy/issues/4492)
options.local_partial_types = True

def serve(self) -> None:
"""Serve requests, synchronously (no thread or fork)."""
Expand Down
4 changes: 0 additions & 4 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,6 @@ def add_invertible_flag(flag: str,
parser.error("Can only find occurrences of class members.")
if len(experiments.find_occurrences) != 2:
parser.error("Can only find occurrences of non-nested class members.")
if options.fine_grained_incremental:
# Fine-grained incremental doesn't support general partial types
# (details in https://github.com/python/mypy/issues/4492)
options.local_partial_types = True

# Set reports.
for flag, val in vars(special_opts).items():
Expand Down
1 change: 1 addition & 0 deletions mypy/test/testdmypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def run_case_once(self, testcase: DataDrivenTestCase, incremental_step: int) ->
if 'fine-grained' in testcase.file:
server_options.append('--experimental')
options.fine_grained_incremental = True
options.local_partial_types = True
self.server = dmypy_server.Server(server_options) # TODO: Fix ugly API
self.server.options = options

Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testfinegrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def build(self,
options.fine_grained_incremental = not build_cache
options.use_fine_grained_cache = enable_cache and not build_cache
options.cache_fine_grained = enable_cache

options.local_partial_types = True
main_path = os.path.join(test_temp_dir, 'main')
with open(main_path, 'w') as f:
f.write(source)
Expand Down
20 changes: 20 additions & 0 deletions test-data/unit/check-dmypy-fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,23 @@ tmp/a.py:1: error: "int" not callable
[delete nonexistent_stub.pyi.2]
[out1]
[out2]

[case testPartialNoneTypeFineGrainedIncremental]
# cmd: mypy -m a b
[file a.py]
import b
b.y
x = None
def f() -> None:
global x
x = ''
[file b.py]
y = 0
[file b.py.2]
y = ''
[out1]
tmp/a.py:3: error: Need type annotation for 'x'
tmp/a.py:6: error: Incompatible types in assignment (expression has type "str", variable has type "None")
[out2]
tmp/a.py:3: error: Need type annotation for 'x'
tmp/a.py:6: error: Incompatible types in assignment (expression has type "str", variable has type "None")
51 changes: 51 additions & 0 deletions test-data/unit/fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -1796,3 +1796,54 @@ def foo(x: Point) -> int:
[out]
==
b.py:3: error: Unsupported operand types for + ("int" and "str")

[case testNonePartialType]
import a
a.y

x = None

def f() -> None:
global x
x = 1
[file a.py]
y = 0
[file a.py.2]
y = ''
[out]
main:4: error: Need type annotation for 'x'
main:8: error: Incompatible types in assignment (expression has type "int", variable has type "None")
==
main:4: error: Need type annotation for 'x'
main:8: error: Incompatible types in assignment (expression has type "int", variable has type "None")

[case testNonePartialType2]
import a
a.y

x = None

def f():
global x
x = 1
[file a.py]
y = 0
[file a.py.2]
y = ''
[out]
main:4: error: Need type annotation for 'x'
==
main:4: error: Need type annotation for 'x'

[case testNonePartialType3]
import a
[file a.py]
[file a.py.2]
y = None
def f() -> None:
global y
y = ''
[out]
==
a.py:1: error: Need type annotation for 'y'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for completes I would add a tests where the error appears in the first run, but not in the second one (like if a user listened and actually added an annotation).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test case.

a.py:4: error: Incompatible types in assignment (expression has type "str", variable has type "None")
0