Skip to content
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

Fix strict none errors in the test subpackage. #2200

Merged
merged 4 commits into from
Oct 3, 2016
Merged

Conversation

gvanrossum
Copy link
Member

This shows several different approaches to dealing with #2199 for p[i].arg.

@ddfisher Thoughts? Maybe we can also commit a mypy.ini containing

[mypy]
show_none_errors = False
[mypy-*mypy/test/*]
show_none_errors = True

This shows several different approaches to dealing with #2199 for
p[i].arg.
sources.append(BuildSource(program_path, module_name, program_text))
sources.append(BuildSource(program_path, module_name,
None if incremental else program_text))
res = None
Copy link
Member Author

@gvanrossum gvanrossum Sep 30, 2016

Choose a reason for hiding this comment

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

This refactor was needed because program_text is previously inferred as str, and that's correct. So this is technically a case of reusing the same variable name with a different type (#1174). [UPDATE: This comment should be one line up.]

@@ -53,11 +53,11 @@ def parse_test_cases(
while i < len(p) and p[i].id != 'case':
if p[i].id == 'file':
# Record an extra file needed for the test case.
files.append((os.path.join(base_path, p[i].arg),
files.append((os.path.join(base_path, p[i].arg or ''),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this really be the empty string, or is this an error condition?

Copy link
Member Author

Choose a reason for hiding this comment

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

IIUC the '' is unreachable -- when id is 'file' arg is never None. A different rewrite would be

arg = p[i].arg
assert arg is not None

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, I rewrote it using the assert, then realized that arg may be None if someone puts [file] in a testcase. That's nonsense. In general the parsing of test cases is pretty crummy, so I don't consider it my job to fix it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. Having an assertion failure in that case seems fine to me.

@ddfisher
Copy link
Collaborator

Not sure we can add that mypy.ini, because suppressing Optional errors suppresses other kinds of errors too...

@gvanrossum
Copy link
Member Author

Adding those flags to mypy.ini should be fine, since they don't have any effect unless you also pass --strict-optional. I guess we should add another mypy run to runtests.py, where it runs mypy --strict-optional mypy and expects no errors.

@ddfisher
Copy link
Collaborator

ddfisher commented Oct 3, 2016

LGTM!

@gvanrossum gvanrossum merged commit 20aea69 into master Oct 3, 2016
@gvanrossum gvanrossum deleted the strict-none-test branch October 3, 2016 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants