Skip to content
Myr

Correct click.edit typing (#2804)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andreas Backx · committed by GitHub · parent b5464b7 · Browse files · 3 files+26 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+26 added−7 removed

  • other:+26 added−7 removed

3 files+26 added−7 removed

modified:src/click/_termui_impl.py+11 added-3 removed
543 unmodified lines
544 raise ClickException(545 _("{editor}: Editing failed: {e}").format(editor=editor, e=e)546 ) from e547548 def edit(self, text: t.AnyStr | None) -> t.AnyStr | None:548 @t.overload549 def edit(self, text: bytes | bytearray) -> bytes | None: ...550551 # We cannot know whether or not the type expected is str or bytes when None552 # is passed, so str is returned as that was what was done before.553 @t.overload554 def edit(self, text: str | None) -> str | None: ...555556 def edit(self, text: str | bytes | bytearray | None) -> str | bytes | None:557 import tempfile558551 if not text:559 if text is None:560 data = b""561 elif isinstance(text, (bytes, bytearray)):562 data = text563 else:
31 unmodified lines
595596 if isinstance(text, (bytes, bytearray)):597 return rv598591 return rv.decode("utf-8-sig").replace("\r\n", "\n") # type: ignore599 return rv.decode("utf-8-sig").replace("\r\n", "\n")600 finally:601 os.unlink(name)602603
167 unmodified lines
modified:src/click/termui.py+14 added-4 removed
684 unmodified lines
685686687@t.overload688def edit(689 text: t.AnyStr,689 text: bytes | bytearray,690 editor: str | None = None,691 env: cabc.Mapping[str, str] | None = None,692 require_save: bool = False,693 extension: str = ".txt",694) -> bytes | None: ...695696697@t.overload698def edit(699 text: str,700 editor: str | None = None,701 env: cabc.Mapping[str, str] | None = None,702 require_save: bool = True,703 extension: str = ".txt",694) -> t.AnyStr: ...704) -> str | None: ...705706707@t.overload708def edit(
6 unmodified lines
715) -> None: ...716717718def edit(709 text: t.AnyStr | None = None,719 text: str | bytes | bytearray | None = None,720 editor: str | None = None,721 env: cabc.Mapping[str, str] | None = None,722 require_save: bool = True,723 extension: str = ".txt",724 filename: str | cabc.Iterable[str] | None = None,715) -> t.AnyStr | None:725) -> str | bytes | bytearray | None:726 r"""Edits the given text in the defined editor. If an editor is given727 (should be the full path to the executable but the regular operating728 system search path is used for finding the executable) it overrides729 the detected editor. Optionally, some environment variables can be
148 unmodified lines
modified:CHANGES.rst+1 added
92 unmodified lines
93 the value from :class:`CliRunner`. :issue:`2817` :pr:`2818`94- ``Option.flag_value`` will no longer have a default value set based on95 ``Option.default`` if ``Option.is_flag`` is ``False``. This results in96 ``Option.default`` not needing to implement `__bool__`. :pr:`2829`97- Incorrect ``click.edit`` typing has been corrected. :pr:`2804`9899Version 8.1.8100-------------101
1117 unmodified lines