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

Do not call is_subtype and is_same_type in third pass of semantic analysis #3977

Closed
ilevkivskyi opened this issue Sep 21, 2017 · 2 comments · Fixed by #4384
Closed

Do not call is_subtype and is_same_type in third pass of semantic analysis #3977

ilevkivskyi opened this issue Sep 21, 2017 · 2 comments · Fixed by #4384
Labels
priority-1-normal refactoring Changing mypy's internals

Comments

@ilevkivskyi
Copy link
Member

We recently eliminated calls to join from semantic analysis and postponed them to callbacks before type checking. However, third pass still calls is_subtype and is_same_type. I think this can cause problems, and it is better to refactor these calls to a later stage (probably also to the callbacks).

This was discovered while working on #3952

@carljm
Copy link
Member

carljm commented Dec 20, 2017

We are seeing a crash due to this issue, when (accidentally) using a module in a Union inside a container type. Repro code is:

import datetime
from typing import List, Union

x: List[Union[int, datetime]] = []

x.append(1)

Obviously the code intends to use datetime.datetime instead of datetime, but it should not cause a crash. Remove either the Union or the List and we instead see the expected "invalid type" error.

Posting here because the backtrace passes through https://github.com/python/mypy/blob/master/mypy/subtypes.py#L81 via semantic analyzer pass 3, so this is the root cause. Let me know if you want a dedicated issue for this crash and I will create one.

Not pasting full traceback since it's easily reproducible with the above code sample.

@carljm
Copy link
Member

carljm commented Dec 20, 2017

#4384 fixes this crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-1-normal refactoring Changing mypy's internals
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants