8000 Don't crash on aliases like C = C by ilevkivskyi · Pull Request #5632 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Don't crash on aliases like C = C #5632

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 3 commits into from
Sep 19, 2018

Conversation

ilevkivskyi
Copy link
Member

Fixes #5631

Unfortunately one still needs to use # type: ignores, mypy has troubles understanding complex conditional definitions like in the issue:

try:
    ConnectionError = ConnectionError
except NameError:
    class ConnectionError(Exception):
        pass

But this is a separate problem, that is harder to solve.

@ilevkivskyi ilevkivskyi requested a review from JukkaL September 18, 2018 13:22
@JelleZijlstra
Copy link
Member

Could you add a test that ensures that if module a has Exception = Exception, it is possible to use a.Exception and it's equivalent to builtins.Exception? I think that's what the pip code from the original issue was doing.

import a
[file a.py]
import lib
x = 1
Copy link
Member

Choose a reason for hiding this comment

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

Thanks! Can you also check that using lib.Exception works here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean in this file? I can add try/except here.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, in this file. Something like try: ... except lib.Exception:.

@ilevkivskyi
Copy link
Member Author

and it's equivalent to builtins.Exception

I am not sure what you mean by this, but even just int = int will confuse mypy. This is unrelated to this particular crash/fix, but is due to the fact that when resolving r.h.s. mypy will just find the Var defined by l.h.s. This is harder to fix, as I mentioned, but it was always like this.

@ilevkivskyi
Copy link
Member Author

@JelleZijlstra @JukkaL what is the situation here? Are there more comments?

@JukkaL
Copy link
Collaborator
JukkaL commented Sep 19, 2018

Looks good to me!

@JelleZijlstra
Copy link
Member

I'm happy with the additional tests.

@ilevkivskyi ilevkivskyi merged commit 5e97a68 into python:master Sep 19, 2018
@ilevkivskyi ilevkivskyi deleted the another-fix-override branch September 19, 2018 19:57
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.

3 participants
0