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

Cannot use types from user-defined package #29

Open
bennn opened this issue Jun 9, 2016 · 5 comments
Open

Cannot use types from user-defined package #29

bennn opened this issue Jun 9, 2016 · 5 comments

Comments

@bennn
Copy link

bennn commented Jun 9, 2016

Here are two files:

# a.py
class A:
  pass
# b.py
from myfolder.a import A
def f()->A:
  return A()

If you put these in a new folder myfolder (along with an empty myfolder/__init__.py file):

  • python myfolder/b.py runs fine
  • retic myfolder/b.py raises an error from line 25 of typefinder.py that the name A is not defined.

Changing ->A to ->Dyn makes the problem go away. Also, doing cd myfolder and replacing from myfolder.a with from a fixes it.

So the problem seems to be that imports from user packages are not available to the typechecker.

@mvitousek
Copy link
Owner

Hm, can you double check that you're running this as you describe? I can't replicate this because for me, python3 myfolder/b.py results in ImportError: No module named 'myfolder'. I get this with Python3.1 through 3.5 so it doesn't seem to be a Python version thing, and my experience matches what I understand to be Python semantics (without a __init__.py file, folders aren't treated as packages that modules can be imported from).

@bennn
Copy link
Author

bennn commented Jun 9, 2016

Oh that's right, I should have said to make myfolder/__init__.py

@mvitousek
Copy link
Owner

Even with an empty __init__.py I get an ImportError with python3. Is there anything in your __init__.py? I still wouldn't expect this code to work, since a.py and b.py are in the same package. If I put b.py outside of myfolder, then the code runs --- but I don't get any errors with Reticulated.

@bennn
Copy link
Author

bennn commented Jun 9, 2016

This is interesting ... first off you're right I should fix my file locations / imports -- the ones above are not good and I didn't realize that.

And here, I think, explains the differences we are seeing:

  1. mkdir test; cd test; mkdir myfolder; ... add a.py and b.py from above (no need for __init__.py I guess)
  2. python3.3.6 myfolder/b.py runs, no problem.
  3. python3.4.4 myfolder/b.py fails. Same for python3.5.
  4. export PYTHONPATH=., now python3.4.4 myfolder/b.py and python3.5 succeed, but retic myfolder/b.py fails.

So I was mixing up Python3.3 and the Python3.4, but there may still be an issue with PYTHONPATH and typechecking.

@mvitousek
Copy link
Owner

Gotcha, thanks. Still can't fully reproduce --- I still get an ImportError with python3.3.6 with the directory structure

test/
  myfolder/
    a.py
    b.py

when running Python from within test. However I do get the behavior you're reporting when I change PYTHONPATH and I'll look into this -- guessing the typechecker isn't correctly grabbing type definitions when the PYTHONPATH isn't what it expects. Thanks!

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

2 participants