Title: difflib pathlike support for {unified,context}_diff() {from,to}file
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.9
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, rhettinger, tim.peters
Priority: normal Keywords:

Created on 2020-01-12 12:58 by BTaskaya, last changed 2020-01-13 03:43 by rhettinger. This issue is now closed.

Messages (2)
msg359847 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2020-01-12 12:58
>>> tuple(difflib.context_diff(["abc"], ["bcd"], fromfile=Path("")))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/", line 1254, in context_diff
    _check_types(a, b, fromfile, tofile, fromfiledate, tofiledate, lineterm)
  File "/usr/local/lib/python3.9/", line 1301, in _check_types
    raise TypeError('all arguments must be str, not: %r' % (arg,))
TypeError: all arguments must be str, not: PosixPath('')

IMHO to and from file arguments should accept PathLike objects. If agreed I can prepare a patch.
msg359885 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-01-13 03:43
Elsewhere users of Path objects must explicitly coerce to str.  For example:  json.dumps(str(Path(""))).   This makes good sense to me.  We don't want to add an dependency on pathlib just to recognize Path objects.
Date User Action Args
2020-01-13 03:43:34rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg359885

resolution: rejected
stage: resolved
2020-01-12 13:49:29xtreaksetnosy: + tim.peters
2020-01-12 12:58:02BTaskayacreate