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

fix[lang]: disallow absolute relative imports #4268

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sandbubbles
Copy link

What I did

How I did it

  • Removed implicit relative imports in submodules, eliminating ambiguity in import paths.
  • Removed the lines that added the current directory to the top of the search paths. As a result, the poke_search_path function may no longer be necessary.

How to verify it

  • added tests

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@sandbubbles sandbubbles changed the title fix[lang]: disallow absolute relative paths fix[lang]: disallow absolute relative imports Oct 1, 2024
Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i think poke_search_paths is probably dead now. can you check? if so, let's remove it!

@@ -789,11 +789,7 @@ def _add_import(
# load an InterfaceT or ModuleInfo from an import.
# raises FileNotFoundError
def _load_import(self, node: vy_ast.VyperNode, level: int, module_str: str, alias: str) -> Any:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess we can fuse load_import_helper right?

# the directory this (currently being analyzed) module is in
self_search_path = Path(self.ast.resolved_path).parent

with self.input_bundle.search_path(
Copy link
Member

@charles-cooper charles-cooper Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think for a relative import, we actually need to override the entire search path. can be a context manager, but something along the lines of

try:
    self.input_bundle.search_paths = [self_search_path]
    self._load_import_helper(...)
finally:
    self.input_bundle.search_paths = original_search_paths

otherwise you can break out of the current directory if the search path falls back to some other path (e.g. like /usr/lib/site-packages/foo/bar)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

import system allows absolute relative imports
2 participants