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

Inform about no explicit export instead of attribute suggestions #9237

Merged
merged 3 commits into from
Sep 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,11 +1802,14 @@ def report_missing_module_attribute(self, import_id: str, source_id: str, import
# Suggest alternatives, if any match is found.
module = self.modules.get(import_id)
if module:
alternatives = set(module.names.keys()).difference({source_id})
matches = best_matches(source_id, alternatives)[:3]
if matches:
suggestion = "; maybe {}?".format(pretty_seq(matches, "or"))
message += "{}".format(suggestion)
if not self.options.implicit_reexport and source_id in module.names.keys():
message += "; implicit reexport disabled"
else:
alternatives = set(module.names.keys()).difference({source_id})
matches = best_matches(source_id, alternatives)[:3]
if matches:
suggestion = "; maybe {}?".format(pretty_seq(matches, "or"))
message += "{}".format(suggestion)
self.fail(message, context, code=codes.ATTR_DEFINED)
self.add_unknown_imported_symbol(imported_id, context)

Expand Down
20 changes: 16 additions & 4 deletions test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ a = 5
[file other_module_2.py]
from other_module_1 import a
[out]
main:2: error: Module 'other_module_2' has no attribute 'a'
main:2: error: Module 'other_module_2' has no attribute 'a'; implicit reexport disabled

[case testNoImplicitReexportRespectsAll]
# flags: --no-implicit-reexport
Expand All @@ -1224,7 +1224,7 @@ from other_module_1 import a, b
__all__ = ('b',)
[builtins fixtures/tuple.pyi]
[out]
main:2: error: Module 'other_module_2' has no attribute 'a'
main:2: error: Module 'other_module_2' has no attribute 'a'; implicit reexport disabled

[case testNoImplicitReexportStarConsideredImplicit]
# flags: --no-implicit-reexport
Expand All @@ -1234,7 +1234,7 @@ a = 5
[file other_module_2.py]
from other_module_1 import *
[out]
main:2: error: Module 'other_module_2' has no attribute 'a'
main:2: error: Module 'other_module_2' has no attribute 'a'; implicit reexport disabled

[case testNoImplicitReexportStarCanBeReexportedWithAll]
# flags: --no-implicit-reexport
Expand All @@ -1248,7 +1248,19 @@ from other_module_1 import *
__all__ = ('b',)
[builtins fixtures/tuple.pyi]
[out]
main:2: error: Module 'other_module_2' has no attribute 'a'
main:2: error: Module 'other_module_2' has no attribute 'a'; implicit reexport disabled

[case textNoImplicitReexportSuggestions]
# flags: --no-implicit-reexport
from other_module_2 import attr_1

[file other_module_1.py]
attr_1 = 5
attr_2 = 6
[file other_module_2.py]
from other_module_1 import attr_1, attr_2
[out]
main:2: error: Module 'other_module_2' has no attribute 'attr_1'; implicit reexport disabled

[case testNoImplicitReexportMypyIni]
# flags: --config-file tmp/mypy.ini
Expand Down