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

Failed to find exact letter case of module name when relative import on Windows OS #18445

Open
trlaitioer opened this issue Jan 11, 2025 · 1 comment
Labels
bug mypy got something wrong

Comments

@trlaitioer
Copy link

Bug Report

Failed to find exact letter case of module name when relative import on Windows OS.

To Reproduce

ModuleName
├─ __init__.py
├─ file.py
├─ main.py

# main.py
from .file import *

Everything is fine when the path is correct with letter case.

mypy .\ModuleName\main.py
Success: no issues found in 1 source file

But if the path of files is wrong with letter case,

mypy .\moduleName\main.py

but there will be an [import-not-found] error.

moduleName\main.py:1: error: Cannot find implementation or library stub for module named "moduleName.file"  [import-not-found]

Your Environment

  • Mypy version used: mypy 1.14.1 (compiled: yes)
@trlaitioer trlaitioer added the bug mypy got something wrong label Jan 11, 2025
@trlaitioer
Copy link
Author

trlaitioer commented Jan 11, 2025

I think it may be the same question with #12880

Edit:
It's more difficult for this one,

  • os.path.normcase always return lowercase
  • os.path.normpath do not normalize case
  • pathlib.Path(...).resolve() will return the abs path, and make drive name uppercase, but do not change the case of directory

It seems no simple solution for this one.

This may help #12880:
replace

path = os.path.normpath(path)

with

path = os.path.normpath(path)
drive, root, path = os.path.splitroot(path)
if drive.endswith(":"):
    drive = drive.upper()
path = os.path.join(drive, root, path)

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

No branches or pull requests

1 participant