~sschwarzer/ftputil#132: 
Simplify `ftputil.error`

The FTPError class and some other code in the ftputil.error module use a keyword argument original_exception. Since ftputil now targets only Python 3.6+ and Python 3 has exception chaining, we don't need a custom mechanism to refer to previous exceptions.

Status
RESOLVED FIXED
Submitter
schwa (unverified)
Assigned to
No-one
Submitted
4 years ago
Updated
4 years ago
Labels
enhancement library

schwa (unverified) 4 years ago · edit

Subtasks:

  • Remove tool.as_bytes. This doesn't seem to be needed (recheck though)
  • Remove tool.same_string_type_as if possible
  • Remove handling of bytes as error strings. Assume that on Python 3, error strings in exceptions are always str
  • Change tool.as_str into two functions:
    • as_str: like the current as_str, but without the os.fspath conversion
    • as_str_path: like the current as_str

The idea is that you wouldn't expect the os.fspath call from a name as_str. The current design mixes up the concept of the conversion to str with the use for paths.

schwa (unverified) 4 years ago · edit

As it turned out, original_exception wasn't used for exception chaining, but only to access str(original_exception), which not always is the same as original_exception.args[0]. For example, the args of socket.gaierror may be (-2, "Name or service not known").

On the other hand, a few more changes were necessary in other areas, but this clearly led to improvements.

In my opinion, the ticket can be closed as of 388435f439d10b49f33db787895c267e9e462412. :-)

Register here or Log in to comment, or comment via email.