Skip to content

Case insensitive when importing modules on Mac #1961

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
DionysusG opened this issue Jul 29, 2016 · 4 comments
Closed

Case insensitive when importing modules on Mac #1961

DionysusG opened this issue Jul 29, 2016 · 4 comments

Comments

@DionysusG
Copy link

DionysusG commented Jul 29, 2016

It seems that mypy fails to deal with the case sensitive imports; it behaves abnormally when importing a object from a module if the object's name is case-incentively the same as the module's name.

Clarify this issue with a example. Suppose we have such a directory structure

├── b
│   ├── \__init__.py
│   └── a.py
└── test.py

in b/a, we define class A and in b/init.py we put from a import A; in test.py we put from b import A. In this situation, python test.py normally emits no error while mypy test.py gives

b/__init__.py:1: error: Name 'A' already defined

This behavior seems to be due to the case insensitivity of mac's file system.

@gvanrossum
Copy link
Member

This doesn't look like it's related to the case insensitive filesystem -- mypy is careful not to be confused by that. I have tried to reconstruct the situation you described but I don't get an error from mypy. I had to change b/__init__.py to

from .a import A

to deal with the relative imports.

If you still want to pursue this, please show the exact contents of your files. If not, please close the issue.

(Also, I fixed up your post slightly -- hope I didn't destroy any information.)

@DionysusG
Copy link
Author

DionysusG commented Aug 1, 2016

Sorry for my inaccuracy and carelessness about describing the file contents. In b/init.py, it is indeed

from .a import A

Also, there is a crucial thing I forgot to mention. In b/a, there is

class A():
    pass

so that import A from a in b/init.py would make sense.

Hope you can reconstruct the situation now.

@gvanrossum
Copy link
Member

No, I still don't see it. Can you zip up the files you are using (the tree b/ and the file test.py) and attach them here? (Or upload somewhere and link from here, or create a gist with all of them? Also, what is the exact mypy invocation you are using, what mypy version are you using, and what platform? (Is it OS X? What version?)

I have tested a variety of case-sensitivity issues and each time mypy does the right thing.

@DionysusG
Copy link
Author

I was using mypy 0.4.1, and mypy 0.4.3 worked perfectly on the constructed situation. By virtualenving different versions, I think this issue was solved in mypy 0.4.2.

Thank you for the patience.

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