Skip to content

Case insensitive when importing modules on Mac #1961

Closed

Description

@DionysusG

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.

Activity

  1. gvanrossum commented on Jul 29, 2016

    @gvanrossum
    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.)

  2. DionysusG commented on Aug 1, 2016

    @DionysusG
    Author

    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.

  3. gvanrossum commented on Aug 1, 2016

    @gvanrossum
    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.

  4. DionysusG commented on Aug 1, 2016

    @DionysusG
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions