python / python/cpython

Inconsistent drive letter case on Windows

Offen
#100,322 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

OS-windows type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
36k
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
558

Beschreibung

Bug report + suggested fix

The os.path.abspath method on windows is inconsistent when pre-pending the drive letter as it can be either upper or lowercase.

It is not entirely clear from Microsoft's documentation (https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew) when this happens exactly, but, a simple way of re-producing the issue is by changing directory and specifying the opposite case letter in the call

C:\Users\kieran>python -c "import os; print(os.path.abspath('.'))"
C:\Users\kieran

C:\Users\kieran>cd c:\Users\kieran\Projects

c:\Users\kieran\Projects>python -c "import os; print(os.path.abspath('.'))"
c:\Users\kieran\Projects

This is very frustrating when trying to compare paths, and, sometimes different tools in the same development environments will run in such a way that they change their drive letter case, leading to issues between those tools or differences inside tests.

I would like to suggest that we enforce the lowercase driver letters by making a small change to https://github.com/python/cpython/blob/0fe61d0838218b18bcff4bf434beba3e8dbcc42b/Modules/posixmodule.c#L4236-L4274

If we were to include an iteration (line 4266) of the buffered path that lowercased the chars up to the colon (guaranteed to be set), this would ensure consistent drive letters.

Your environment

Python 3.9.6
Microsoft Windows 10 Pro - 10.0.19044 Build 19044
x64-based PC

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem Windows-Pfadbehandlungscode in Modules/posixmodule.c rund um die verlinkten Zeilen und reproduziere anschließend das Verhalten mit den im Bericht aufgeführten os.path.abspath-Befehlen. Bestätige, wie der Laufwerksbuchstabe ermittelt wird, und definiere als abgeschlossen, dass die Groß-/Kleinschreibung von Laufwerksbuchstaben in absoluten Windows-Pfaden konsistent ist und das relevante Verhalten durch Tests abgedeckt wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c, python
Bereich
operating-systems
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.