Skip to content

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

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

Open
trlaitioer opened this issue Jan 11, 2025 · 2 comments
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)

@wyattscarpenter
Copy link
Contributor

wyattscarpenter commented May 19, 2025

I was able to replicate this issue.

Here are the examples translated into cmdline.test tests:

[case testCmdlinePackageWindowsCaseBaseCase]
# cmd: mypy .\ModuleName\main.py
[file ModuleName/__init__.py]
[file ModuleName/main.py]
from .file import *
[file ModuleName/file.py]

[case testCmdlinePackageWindowsCase]
# cmd: mypy .\moduleName\main.py
[file ModuleName/__init__.py]
[file ModuleName/main.py]
from .file import *
[file ModuleName/file.py]

(Both of them "should" pass, but only the first one does.)

I guess you would have to make sure they only run on Windows; I don't know how to do that.

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

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy