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

Include a note when user forgets to import something from the typing module #6770

Merged
merged 5 commits into from May 6, 2019

Conversation

@cs-cordero
Copy link
Contributor

commented May 6, 2019

Fixes #4317

@onlined

This comment has been minimized.

Copy link
Contributor

commented May 6, 2019

I think you should do the same thing in the new semantic analyzer.

@JukkaL
Copy link
Collaborator

left a comment

Thanks! Some existing test cases also need to be updated to include the new note.

# User probably forgot to import these types.
unimported_module, suggestion = TYPES_FOR_UNIMPORTED_HINTS[name.lower()]
hint = (
f'Did you forget to import it from "{unimported_module}"?'

This comment has been minimized.

Copy link
@JukkaL

JukkaL May 6, 2019

Collaborator

Unfortunately we can't use f-strings since mypy still supports Python 3.5.

This comment has been minimized.

Copy link
@cs-cordero

cs-cordero May 6, 2019

Author Contributor

👍

'tuple': ('typing', 'from typing import Tuple'),
'typevar': ('typing', 'from typing import TypeVar'),
'union': ('typing', 'from typing import Union'),
'cast': ('typing', 'from typing import cast'),

This comment has been minimized.

Copy link
@JukkaL

JukkaL May 6, 2019

Collaborator

Since all of these follow the same pattern, we could perhaps avoid some redundancy. One idea would be to just have a list/set of full names (typing.Any, typing.Callable, ...) and we can derive the other information (lower case version, from typing import Foo) from them.

This comment has been minimized.

Copy link
@cs-cordero

cs-cordero May 6, 2019

Author Contributor

👍

@cs-cordero

This comment has been minimized.

Copy link
Contributor Author

commented May 6, 2019

Thanks! I will update both the new semantic analyzer and the old semantic analyzer. And it also looks like I missed a few tests, so I'll fix that too.

@ilevkivskyi
Copy link
Collaborator

left a comment

Look great, thank you!

@ilevkivskyi ilevkivskyi merged commit 2e098a2 into python:master May 6, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@cs-cordero cs-cordero deleted the cs-cordero:import-hinting branch May 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.