-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
fix: prevent phantom cycles from package-module name collisions #3784
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
Closed
hopstreax
wants to merge
1
commit into
Graphify-Labs:v8
from
hopstreax:fix/3777-module-package-conflation
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,3 +150,103 @@ def test_python_parameter_return_and_generic_contexts(tmp_path: Path): | |
| assert ("process()", "Payload", "parameter_type") in pairs | ||
| assert ("process()", "Result", "return_type") in pairs | ||
| assert ("process_many()", "Payload", "generic_arg") in pairs | ||
|
|
||
|
|
||
| def test_issue_3777_package_module_collision_phantom_cycle_absent(tmp_path: Path): | ||
| from graphify.analyze import find_import_cycles | ||
| from graphify.build import build_from_json | ||
|
|
||
| nettacker_py = _write( | ||
| tmp_path / "nettacker.py", | ||
| "from nettacker.main import run\n\ndef cli():\n run()\n", | ||
| ) | ||
| init_py = _write(tmp_path / "nettacker/__init__.py", "") | ||
| main_py = _write( | ||
| tmp_path / "nettacker/main.py", | ||
| "from nettacker.core.app import Nettacker\n\ndef run():\n return Nettacker()\n", | ||
| ) | ||
| app_py = _write( | ||
| tmp_path / "nettacker/core/app.py", | ||
| "from nettacker import logger\n\nclass Nettacker:\n def start(self):\n logger.log_info('start')\n", | ||
| ) | ||
| logger_py = _write( | ||
| tmp_path / "nettacker/logger.py", | ||
| "def log_info(msg):\n print(msg)\n", | ||
| ) | ||
|
|
||
| result = extract( | ||
| [nettacker_py, init_py, main_py, app_py, logger_py], | ||
| cache_root=tmp_path, | ||
| root=tmp_path, | ||
| ) | ||
|
|
||
| app_file = _node_id(result, "app.py", "nettacker/core/app.py") | ||
| logger_file = _node_id(result, "logger.py", "nettacker/logger.py") | ||
| nettacker_file = _node_id(result, "nettacker.py", "nettacker.py") | ||
|
|
||
| assert _has_edge(result, app_file, logger_file, "imports_from") | ||
| assert not _has_edge(result, app_file, nettacker_file, "imports_from") | ||
|
|
||
| graph = build_from_json(result) | ||
| assert find_import_cycles(graph) == [] | ||
|
|
||
|
|
||
| def test_issue_3777_nested_module_package_collision_resolves_to_submodule(tmp_path: Path): | ||
|
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.
fans out to 6 callees (efferent coupling). Grounded coupling-delta finding (deterministic), not an LLM guess. |
||
| from graphify.analyze import find_import_cycles | ||
| from graphify.build import build_from_json | ||
|
|
||
| runner_py = _write( | ||
| tmp_path / "pkg/runner.py", | ||
| "from pkg.runner.step import run\n\ndef start():\n run()\n", | ||
| ) | ||
| init_py = _write(tmp_path / "pkg/runner/__init__.py", "") | ||
| step_py = _write( | ||
| tmp_path / "pkg/runner/step.py", | ||
| "from pkg.runner import helper\n\ndef run():\n helper.work()\n", | ||
| ) | ||
| helper_py = _write( | ||
| tmp_path / "pkg/runner/helper.py", | ||
| "def work():\n pass\n", | ||
| ) | ||
|
|
||
| result = extract( | ||
| [runner_py, init_py, step_py, helper_py], | ||
| cache_root=tmp_path, | ||
| root=tmp_path, | ||
| ) | ||
|
|
||
| step_file = _node_id(result, "step.py", "pkg/runner/step.py") | ||
| helper_file = _node_id(result, "helper.py", "pkg/runner/helper.py") | ||
| runner_file = _node_id(result, "runner.py", "pkg/runner.py") | ||
|
|
||
| assert _has_edge(result, step_file, helper_file, "imports_from") | ||
| assert not _has_edge(result, step_file, runner_file, "imports_from") | ||
|
|
||
| graph = build_from_json(result) | ||
| assert find_import_cycles(graph) == [] | ||
|
|
||
|
|
||
| def test_issue_3777_namespace_package_submodule_import(tmp_path: Path): | ||
| sub = _write(tmp_path / "ns/sub.py", "def helper():\n pass\n") | ||
| consumer = _write(tmp_path / "ns/consumer.py", "from ns import sub\n") | ||
|
|
||
| result = extract([sub, consumer], cache_root=tmp_path, root=tmp_path) | ||
|
|
||
| consumer_file = _node_id(result, "consumer.py", "ns/consumer.py") | ||
| sub_file = _node_id(result, "sub.py", "ns/sub.py") | ||
|
|
||
| assert _has_edge(result, consumer_file, sub_file, "imports_from") | ||
|
|
||
|
|
||
| def test_issue_3777_standalone_module_import_unaffected(tmp_path: Path): | ||
| standalone = _write(tmp_path / "standalone.py", "def fn():\n return 42\n") | ||
| consumer = _write(tmp_path / "consumer.py", "from standalone import fn\n") | ||
|
|
||
| result = extract([standalone, consumer], cache_root=tmp_path, root=tmp_path) | ||
|
|
||
| consumer_file = _node_id(result, "consumer.py", "consumer.py") | ||
| standalone_file = _node_id(result, "standalone.py", "standalone.py") | ||
| fn_symbol = _node_id(result, "fn()", "standalone.py") | ||
|
|
||
| assert _has_edge(result, consumer_file, standalone_file, "imports_from") | ||
| assert _has_edge(result, consumer_file, fn_symbol, "imports") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
test_issue_3777_package_module_collision_phantom_cycle_absent()fans out to 6 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.