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

Always infer `in` operator as returning `bool` #5688

Merged
merged 4 commits into from Feb 1, 2019

Conversation

@TV4Fun
Copy link
Contributor

commented Sep 28, 2018

Resolves #5656

@TV4Fun

This comment has been minimized.

Copy link
Contributor Author

commented Sep 28, 2018

Tangentially related: Is there a way to have the test suite do type checks on Mypy's own code?

@@ -1686,6 +1686,8 @@ def visit_ellipsis(self, e: EllipsisExpr) -> Type:

def visit_op_expr(self, e: OpExpr) -> Type:
"""Type check a binary operator expression."""
if e.op == 'in':

This comment has been minimized.

Copy link
@JelleZijlstra

JelleZijlstra Sep 28, 2018

Collaborator

Does this mean that we won't check type errors within the subexpressions of the in expressions?

Concretely, does mypy still report an error on code like 1 in ([1] + ['x'])?

This comment has been minimized.

Copy link
@TV4Fun

TV4Fun Sep 29, 2018

Author Contributor

The example you gave still produces an error, but just to be on the safe side, I've added some extra type checking, and a test to make sure this is still an error.

@JelleZijlstra

This comment has been minimized.

Copy link
Collaborator

commented Sep 28, 2018

We run a self-check (mypy typechecking itself) as part of the test suite.

@TV4Fun

This comment has been minimized.

Copy link
Contributor Author

commented Sep 29, 2018

@JelleZijlstra, the reason I asked about type checking Mypy, is that before I submitted this PR, I ran the full test suite with pytest, but there was still a type error that was only caught by the CI build after I submitted.

@gvanrossum

This comment has been minimized.

Copy link
Member

commented Sep 29, 2018

before I submitted this PR, I ran the full test suite with pytest, but there was still a type error that was only caught by the CI build after I submitted.

That's because CI does a bit more than just run pytest. Check out the contents of .travis.yml and appveyor.yml to see what.

You can type-check mypy with itself using something like python3 -m mypy --config-file mypy_self_check.ini mypy.

@TV4Fun

This comment has been minimized.

Copy link
Contributor Author

commented Sep 30, 2018

Thanks for that information @gvanrossum. I might suggest adding that to the documentation for tests to run before submitting a PR.

@gvanrossum

This comment has been minimized.

Copy link
Member

commented Sep 30, 2018

@gvanrossum

This comment has been minimized.

Copy link
Member

commented Oct 1, 2018

I forgot one thing. (It's also not in any README file.) There's a script runtests.py that runs all the tests, including the self tests. I was reminded of this by #5702.

gvanrossum added a commit that referenced this pull request Oct 1, 2018

@jonapich

This comment has been minimized.

Copy link

commented Oct 2, 2018

Am I seeing the same behavior with == operator?

    def __eq__(self, other: Any) -> bool:
        return other == self.value

warning: Returning Any from function declared to return "bool"

@ilevkivskyi

This comment has been minimized.

Copy link
Collaborator

commented Oct 2, 2018

@jonapich
No, you don't:

>>> class C:
...     def __eq__(self, other):
...         return 'surprise'
...     def __contains__(self, other):
...         return 'no way'
... 
>>> 1 in C()
True
>>> 1 == C()
'surprise'
@jonapich

This comment has been minimized.

Copy link

commented Oct 2, 2018

🙊

🏃

TV4Fun added a commit to TV4Fun/mypy that referenced this pull request Oct 4, 2018

@msullivan
Copy link
Collaborator

left a comment

This seems solid to me. If you rebase and fix merge conflicts I think we can merge it.

@msullivan

This comment has been minimized.

Copy link
Collaborator

commented Feb 1, 2019

I went and rebased this and will merge it now

@msullivan msullivan merged commit 83775ed into python:master Feb 1, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.