Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

difflib pathlike support for {unified,context}_diff() {from,to}file #83492

Closed
isidentical opened this issue Jan 12, 2020 · 2 comments
Closed
Labels
3.9 only security fixes stdlib Python modules in the Lib dir

Comments

@isidentical
Copy link
Sponsor Member

BPO 39311
Nosy @tim-one, @rhettinger, @isidentical

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-01-13.03:43:34.704>
created_at = <Date 2020-01-12.12:58:02.508>
labels = ['library', '3.9']
title = 'difflib pathlike support for {unified,context}_diff() {from,to}file'
updated_at = <Date 2020-01-13.03:43:34.695>
user = 'https://github.com/isidentical'

bugs.python.org fields:

activity = <Date 2020-01-13.03:43:34.695>
actor = 'rhettinger'
assignee = 'none'
closed = True
closed_date = <Date 2020-01-13.03:43:34.704>
closer = 'rhettinger'
components = ['Library (Lib)']
creation = <Date 2020-01-12.12:58:02.508>
creator = 'BTaskaya'
dependencies = []
files = []
hgrepos = []
issue_num = 39311
keywords = []
message_count = 2.0
messages = ['359847', '359885']
nosy_count = 3.0
nosy_names = ['tim.peters', 'rhettinger', 'BTaskaya']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue39311'
versions = ['Python 3.9']

@isidentical
Copy link
Sponsor Member Author

>>> tuple(difflib.context_diff(["abc"], ["bcd"], fromfile=Path("example.py")))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/difflib.py", line 1254, in context_diff
    _check_types(a, b, fromfile, tofile, fromfiledate, tofiledate, lineterm)
  File "/usr/local/lib/python3.9/difflib.py", line 1301, in _check_types
    raise TypeError('all arguments must be str, not: %r' % (arg,))
TypeError: all arguments must be str, not: PosixPath('example.py')

IMHO to and from file arguments should accept PathLike objects. If agreed I can prepare a patch.

@isidentical isidentical added 3.9 only security fixes stdlib Python modules in the Lib dir labels Jan 12, 2020
@rhettinger
Copy link
Contributor

Elsewhere users of Path objects must explicitly coerce to str. For example: json.dumps(str(Path("example.py"))). This makes good sense to me. We don't want to add an dependency on pathlib just to recognize Path objects.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

2 participants