Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30137 closed Cleanup/optimization (fixed)

Replace use of OSError aliases with OSError (IOError, EnvironmentError, WindowsError, mmap.error, socket.error, select.error)

Reported by: Jon Dufresne Owned by: nobody
Component: Uncategorized Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Starting with Python 3.3, EnvironmentError, IOError, WindowsError, socket.error, select.error and mmap.error are aliases of OSError. With this in mind, the Django code base can be cleaned up.

For additional details, see the Python 3.3 release notes:

https://docs.python.org/3/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy

You don’t have to worry anymore about choosing the appropriate exception type between OSError, IOError, EnvironmentError, WindowsError, mmap.error, socket.error or select.error. All these exception types are now only one: OSError. The other names are kept as aliases for compatibility reasons.

Additionally, since Python 3.4, SMTPException is subclass of OSError . So exception handles catching both can be simplified to just OSError.

https://docs.python.org/3/library/smtplib.html#smtplib.SMTPException

Subclass of OSError that is the base exception class for all the other exceptions provided by this module.

Changed in version 3.4: SMTPException became subclass of OSError

Change History (5)

comment:2 by Nick Pope, 5 years ago

Triage Stage: UnreviewedAccepted

Now we're targeting Python ≥ 3.6 for Django 3.0 this is a nice clean up.

comment:3 by Mariusz Felisiak, 5 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Tim Graham <timograham@…>, 5 years ago

Resolution: fixed
Status: newclosed

In 7785e03b:

Fixed #30137 -- Replaced OSError aliases with the canonical OSError.

Used more specific errors (e.g. FileExistsError) as appropriate.

comment:5 by GitHub <noreply@…>, 5 years ago

In 9a0cc54:

Refs #30137 -- Fixed template test on Windows.

Broken in 7785e03ba89aafbd949191f126361fb9103cb980.

Note: See TracTickets for help on using tickets.
Back to Top