Opened 3 weeks ago

Closed 3 weeks ago

#132 closed enhancement (fixed)

Simplify `ftputil.error`

Reported by: schwa Owned by: schwa
Priority: minor Milestone: 4.0.0
Component: Library Version: 3.4
Keywords: original exception error handling original_exception Cc:

Description

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.

Change History (2)

comment:1 Changed 3 weeks ago by schwa

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.

Last edited 3 weeks ago by schwa (previous) (diff)

comment:2 Changed 3 weeks ago by schwa

Resolution: fixed
Status: assignedclosed

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 [616e46ca84e0]. :-)

Note: See TracTickets for help on using tickets.