Patchwork [1,of,7] encoding: make getcols() raise exception explicitly

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 16, 2019, 11:59 a.m.
Message ID <788e92d3589b8007e47d.1573905577@mimosa>
Download mbox | patch
Permalink /patch/43294/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 16, 2019, 11:59 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1573886601 -32400
#      Sat Nov 16 15:43:21 2019 +0900
# Node ID 788e92d3589b8007e47db7533d01654911335cc5
# Parent  bde66eb4051df0c4ca952dcb306bd9a2fa238acb
encoding: make getcols() raise exception explicitly

This helps pytype.

  File "mercurial/encoding.py", line 329, in getcols: bad option in return
  type [bad-return-type]
  Expected: bytes
  Actually returned: None
Gregory Szorc - Nov. 16, 2019, 7:36 p.m.
On Sat, Nov 16, 2019 at 6:50 AM Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1573886601 -32400
> #      Sat Nov 16 15:43:21 2019 +0900
> # Node ID 788e92d3589b8007e47db7533d01654911335cc5
> # Parent  bde66eb4051df0c4ca952dcb306bd9a2fa238acb
> encoding: make getcols() raise exception explicitly
>

Queued this series. Thanks for the typing improvements!


>
> This helps pytype.
>
>   File "mercurial/encoding.py", line 329, in getcols: bad option in return
>   type [bad-return-type]
>   Expected: bytes
>   Actually returned: None
>
> diff --git a/mercurial/encoding.py b/mercurial/encoding.py
> --- a/mercurial/encoding.py
> +++ b/mercurial/encoding.py
> @@ -327,6 +327,7 @@ def getcols(s, start, c):
>          t = s[start:x]
>          if colwidth(t) == c:
>              return t
> +    raise ValueError('substring not found')
>
>
>  def trim(s, width, ellipsis=b'', leftside=False):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -327,6 +327,7 @@  def getcols(s, start, c):
         t = s[start:x]
         if colwidth(t) == c:
             return t
+    raise ValueError('substring not found')
 
 
 def trim(s, width, ellipsis=b'', leftside=False):