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

Handle sys.path.append for more convenience #498

Closed
p-avital opened this issue Oct 16, 2020 · 3 comments
Closed

Handle sys.path.append for more convenience #498

p-avital opened this issue Oct 16, 2020 · 3 comments

Comments

@p-avital
Copy link

p-avital commented Oct 16, 2020

Hello there,

A rather common pattern in my teams is the use of sys.path.append(os.path.dirname(__file__)) in the entry point to ensure the libs are accessible for imports.

This is a rather easy pattern to find, do you think this could be used to add some folders to the PYTHON_PATH Pylance considers ? This would be useful when the entry point is not located at the workspace's root :)

It is a bit hacky though, so I'd understand if you don't want to do it

@ALLinLLM
Copy link

@p-avital That's really useful!

And for me, from dirA.util import xxx is also a common pattern

my_project
|--dirA
| |__util.py
|--dirB
|__main.py

@erictraut
Copy link
Contributor

erictraut commented Oct 19, 2020

@p-avital, a static type checker cannot handle dynamic changes to system paths. If you are interested in using the functionality provided by a static type checker, you should avoid using this technique.

@vegetable09, this should already work fine. If you see a specific problem, please file a separate issue. Thanks!

@jakebailey
Copy link
Member

Yeah, this would be a hack; this is a bit more evaluation that I think we're comfortable with.

Also see #253, since it seems like you're talking about scripts (which natively have this "add the script's folder to sys.path behavior).

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

No branches or pull requests

4 participants