Skip to content

Possible regression in 7.1: click.edit() no longer accepts Path objects for filename #1520

@samueldg

Description

@samueldg

Expected Behavior

In click 7.0, you could pass a pathlib.Path object as click.edit()'s filename parameter. In 7.1 this fails with a TypeError

To reproduce, create a regression.py file like so:

import click
from pathlib import Path
click.edit(filename=Path('here.txt'))

With 7.0:

$ pip install 'click==7.0'
$ python regression.py
Press ENTER or type command to continue

(editor is actually launched)

Actual Behavior

With 7.1:

$ pip install 'click==7.1'
$ python regression.py
Traceback (most recent call last):
  File "regression.py", line 4, in <module>
    click.edit(filename=Path('here.txt'))
  File "/Users/samuel/workspace/tmp/click-regression/.venv/lib/python3.7/site-packages/click/termui.py", line 588, in edit
    editor.edit_file(filename)
  File "/Users/samuel/workspace/tmp/click-regression/.venv/lib/python3.7/site-packages/click/_termui_impl.py", line 466, in edit_file
    "{} {}".format(shlex_quote(editor), shlex_quote(filename)),
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/shlex.py", line 319, in quote
    if _find_unsafe(s) is None:
TypeError: expected string or bytes-like object

Although the ability to use Path wasn't documented explicitly, it seems desirable from a compatibility perspective.

Environment

  • Python version: Python 3.7.7
  • Click version: 7.1

Other

Based on the traceback, looks like it could be related to #1470

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions