Python documentation says that
os.rename(src, dst)
… On Windows, if dst already exists, OSError will be raised even if it is a file …
However, for me it raises WindowsError. Is there a mistake in the documentation?
The second part of the question (more general, but inspired by the problem formulated above):
UPD I am sorry, the second part of the question was incorrect. WindowsError is indeed catched by except OSError as it should.
Since OSError is a superclass of WindowsError, just catch the OSError.
FWIW, the core devs are free to raise an exception more specific than the minimum promised by the docs.
Also, the following code works fine for me (Python2.7.2 running on WindowsXP):