[Python-Dev] Case sensitive import

Tim Peters tim.one@home.com
Fri, 2 Feb 2001 03:39:40 -0500


[Steven D. Majewski]
> ...
> Is there any consensus on how to deal with this ?

No, else it would have been done already.

> ...
> So it appears that I don't understand the issues on other
> platforms and what CHECK_IMPORT_CASE intends to fix.

It started on Windows.  The belief was that people (not developers -- your
personal testimony doesn't count, and neither does mine <0.3 wink>) on
case-insensitive file systems don't pay much attention to the case of names
they type.  So the belief was (perhaps it even happened -- I wasn't paying
attention at the time, since I was a Unix Dweeb then) people would
carelessly write, e.g.,

    import String

and then pick up some accidental String.py module instead of the builtin
"string" they intended.  So Python started checking for case-match on
Windows, and griping if the *first* module name Windows returns didn't match
case exactly.  OK, it's actually more complicated than that, because some
network filesystems used on Windows actually changed all filenames to
uppercase.  So there's an exception made for that wart too.

Anyway, looks like a blind guess to me whether this actually does anyone any
good.  For efficiency, it *does* stop at the first, so if the user typed

    import string

*intending* to import String.py, they'd never hear about their mistake.  So
it doesn't really address the whole (putative) problem regardless.  It only
gripes if the first case-insensitive match on the path doesn't match
exactly.

However, *if* it makes sense on Windows, then it makes exactly as much sense
on "the standard filesystem ... Apple's HFS+, which is case preserving but
case insensitive" -- same deal as Windows.  I see no reason to believe that
non-developer users on Macs are going to be more case-savvy than on Windows
(or is there a reason to believe that?).

Another wart is that it's easy to create Python modules that import fine on
Unix, but blow up if you try to run them on Windows (or HFS+).  That sucks
too, and isn't just theoretical (although in practice it's a lot less common
than tracking down binary files opened in text mode!).

The Cygwin people have a related problem:  they *are* trying to emulate
Unix, but doing so on a Windows box, so, umm, enjoy the best of all worlds.

I'd rather see the same rule used everywhere (keep going until finding an
exact match), and tough beans to the person who writes

    import String

on Windows (or Mac) intending "string".  Windows probably still needs a
unique wart to deal with case-destroying network filesystems, though.

It's still terrible style to *rely* on case-sensitivity in file names, and
all such crap should be purged from the Python distribution regardless.

guido-will-agree-with-exactly-one-of-these-claims<wink>-ly y'rs  - tim