-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat: stubgen warn some modules are ignored #13919
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,8 +60,10 @@ def test_files_found(self) -> None: | |
| self.make_file("subdir", "b.py") | ||
| os.mkdir(os.path.join("subdir", "pack")) | ||
| self.make_file("subdir", "pack", "__init__.py") | ||
| os.mkdir(os.path.join("subdir", "vendor")) | ||
| self.make_file("subdir", "vendor", "a.py") | ||
| opts = parse_options(["subdir"]) | ||
| py_mods, c_mods = collect_build_targets(opts, mypy_options(opts)) | ||
| py_mods, c_mods, ignored_py_mods = collect_build_targets(opts, mypy_options(opts)) | ||
| assert_equal(c_mods, []) | ||
| files = {mod.path for mod in py_mods} | ||
| assert_equal( | ||
|
|
@@ -72,6 +74,8 @@ def test_files_found(self) -> None: | |
| os.path.join("subdir", "b.py"), | ||
| }, | ||
| ) | ||
| ignored_files = {mod.path for mod in ignored_py_mods} | ||
| assert_equal(ignored_files, {os.path.join("subdir", "vendor", "a.py")}) | ||
| finally: | ||
| os.chdir(current) | ||
|
|
||
|
|
@@ -85,8 +89,11 @@ def test_packages_found(self) -> None: | |
| self.make_file("pack", "__init__.py", content="from . import a, b") | ||
| self.make_file("pack", "a.py") | ||
| self.make_file("pack", "b.py") | ||
| os.mkdir(os.path.join("pack", "vendor")) | ||
| self.make_file("pack", "vendor", "__init__.py") | ||
| self.make_file("pack", "vendor", "a.py") | ||
| opts = parse_options(["-p", "pack"]) | ||
| py_mods, c_mods = collect_build_targets(opts, mypy_options(opts)) | ||
| py_mods, c_mods, ignored_py_mods = collect_build_targets(opts, mypy_options(opts)) | ||
| assert_equal(c_mods, []) | ||
| files = {os.path.relpath(mod.path or "FAIL") for mod in py_mods} | ||
| assert_equal( | ||
|
|
@@ -97,11 +104,19 @@ def test_packages_found(self) -> None: | |
| os.path.join("pack", "b.py"), | ||
| }, | ||
| ) | ||
| ignored_files = {os.path.relpath(mod.path or "FAIL") for mod in ignored_py_mods} | ||
| assert_equal( | ||
| ignored_files, | ||
| { | ||
| os.path.join("pack", "vendor", "__init__.py"), | ||
| os.path.join("pack", "vendor", "a.py"), | ||
| }, | ||
| ) | ||
| finally: | ||
| os.chdir(current) | ||
|
|
||
| @unittest.skipIf(sys.platform == "win32", "clean up fails on Windows") | ||
| def test_module_not_found(self) -> None: | ||
| def test_module_found(self) -> None: | ||
| current = os.getcwd() | ||
| captured_output = io.StringIO() | ||
| sys.stdout = captured_output | ||
|
|
@@ -110,8 +125,12 @@ def test_module_not_found(self) -> None: | |
| os.chdir(tmp) | ||
| self.make_file(tmp, "mymodule.py", content="import a") | ||
| opts = parse_options(["-m", "mymodule"]) | ||
| py_mods, c_mods = collect_build_targets(opts, mypy_options(opts)) | ||
| py_mods, c_mods, ignored_py_mods = collect_build_targets(opts, mypy_options(opts)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well I checked this test case and found its name I confirmed that I didn't make any unintentional changes by checking out master branch of mypy, and modified I fixed test case name and add assertions for variables py_mods, c_mods, ignored_py_mods by 4f44401. |
||
| assert captured_output.getvalue() == "" | ||
| files = {os.path.relpath(mod.path or "FAIL") for mod in py_mods} | ||
| assert_equal(files, {"mymodule.py"}) | ||
| assert_equal(c_mods, []) | ||
| assert_equal(ignored_py_mods, []) | ||
| finally: | ||
| sys.stdout = sys.__stdout__ | ||
| os.chdir(current) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is
"FAIL"?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact I wrote in the same way as
filesinitialized here.mypy/mypy/test/teststubgen.py
Line 98 in 1104810
StubSource.path may be None, so I guess the original code intend to express failure of module finding and also avoiding error which caused by passing None to os.path.relpath.
Maybe "NOT_FOUND" or just skipping mod without mod.path like below is better. Which do you think is better?