From d583934770c65dcf7c418a903c5cca741e925701 Mon Sep 17 00:00:00 2001 From: dosisod <39638017+dosisod@users.noreply.github.com> Date: Sun, 7 Jan 2024 23:44:15 -0800 Subject: [PATCH] Improve error messages for FURB173, bump version for release --- pyproject.toml | 2 +- refurb/checks/readability/use_dict_union.py | 11 +++---- test/data/err_173.txt | 32 ++++++++++----------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index de9e411..7b5a94b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "refurb" -version = "1.26.0" +version = "1.27.0" description = "A tool for refurbish and modernize Python codebases" authors = ["dosisod"] license = "GPL-3.0-only" diff --git a/refurb/checks/readability/use_dict_union.py b/refurb/checks/readability/use_dict_union.py index 07bbe4f..619f8ad 100644 --- a/refurb/checks/readability/use_dict_union.py +++ b/refurb/checks/readability/use_dict_union.py @@ -90,8 +90,8 @@ def check(node: DictExpr | CallExpr, errors: list[Error], settings: Settings) -> if not is_builtin_mapping(star_expr): return - old.append(f"**x{index}") - new.append(f"x{index}") + old.append(f"**{stringify(star_expr)}") + new.append(stringify(star_expr)) index += 1 @@ -99,11 +99,8 @@ def check(node: DictExpr | CallExpr, errors: list[Error], settings: Settings) -> old.append("...") new.append("{...}") - # Hack to keep list sorted while removing neighboring duplicates - unique_unsorted = dict.fromkeys - - old_msg = ", ".join(unique_unsorted(old)) - new_msg = " | ".join(unique_unsorted(new)) + old_msg = ", ".join(old) + new_msg = " | ".join(new) msg = f"Replace `{{{old_msg}}}` with `{new_msg}`" diff --git a/test/data/err_173.txt b/test/data/err_173.txt index 58c5ec3..54617d6 100644 --- a/test/data/err_173.txt +++ b/test/data/err_173.txt @@ -1,19 +1,19 @@ -test/data/err_173.py:7:5 [FURB173]: Replace `{**x1, **x2}` with `x1 | x2` -test/data/err_173.py:8:5 [FURB173]: Replace `{**x1, ...}` with `x1 | {...}` -test/data/err_173.py:9:5 [FURB173]: Replace `{**x1, ...}` with `x1 | {...}` -test/data/err_173.py:10:5 [FURB173]: Replace `{..., **x1}` with `{...} | x1` -test/data/err_173.py:11:5 [FURB173]: Replace `{..., **x1}` with `{...} | x1` -test/data/err_173.py:12:5 [FURB173]: Replace `{..., **x1, **x2}` with `{...} | x1 | x2` -test/data/err_173.py:13:5 [FURB173]: Replace `{**x1, **x2, ...}` with `x1 | x2 | {...}` -test/data/err_173.py:14:5 [FURB173]: Replace `{**x1, **x2, **x3}` with `x1 | x2 | x3` -test/data/err_173.py:15:5 [FURB173]: Replace `{**x1, **x2, **x3, **x4}` with `x1 | x2 | x3 | x4` -test/data/err_173.py:16:5 [FURB173]: Replace `{**x1, **x2, **x3, **x4, **x5}` with `x1 | x2 | x3 | x4 | x5` -test/data/err_173.py:17:5 [FURB173]: Replace `{**x1, **x2, **x3, **x4, ...}` with `x1 | x2 | x3 | x4 | {...}` -test/data/err_173.py:22:5 [FURB173]: Replace `{..., **x1}` with `{...} | x1` -test/data/err_173.py:25:5 [FURB173]: Replace `{..., **x1}` with `{...} | x1` -test/data/err_173.py:28:5 [FURB173]: Replace `{..., **x1}` with `{...} | x1` -test/data/err_173.py:31:5 [FURB173]: Replace `{..., **x1}` with `{...} | x1` -test/data/err_173.py:34:5 [FURB173]: Replace `{..., **x1}` with `{...} | x1` +test/data/err_173.py:7:5 [FURB173]: Replace `{**x, **y}` with `x | y` +test/data/err_173.py:8:5 [FURB173]: Replace `{**x, ...}` with `x | {...}` +test/data/err_173.py:9:5 [FURB173]: Replace `{**x, ..., ...}` with `x | {...} | {...}` +test/data/err_173.py:10:5 [FURB173]: Replace `{..., **x}` with `{...} | x` +test/data/err_173.py:11:5 [FURB173]: Replace `{..., ..., **x}` with `{...} | {...} | x` +test/data/err_173.py:12:5 [FURB173]: Replace `{..., **x, **y}` with `{...} | x | y` +test/data/err_173.py:13:5 [FURB173]: Replace `{**x, **y, ...}` with `x | y | {...}` +test/data/err_173.py:14:5 [FURB173]: Replace `{**x, **y, **z}` with `x | y | z` +test/data/err_173.py:15:5 [FURB173]: Replace `{**x, **y, **z, **x}` with `x | y | z | x` +test/data/err_173.py:16:5 [FURB173]: Replace `{**x, **y, **z, **x, **x}` with `x | y | z | x | x` +test/data/err_173.py:17:5 [FURB173]: Replace `{**x, **y, **z, **x, ...}` with `x | y | z | x | {...}` +test/data/err_173.py:22:5 [FURB173]: Replace `{..., **chainmap}` with `{...} | chainmap` +test/data/err_173.py:25:5 [FURB173]: Replace `{..., **counter}` with `{...} | counter` +test/data/err_173.py:28:5 [FURB173]: Replace `{..., **ordereddict}` with `{...} | ordereddict` +test/data/err_173.py:31:5 [FURB173]: Replace `{..., **dd}` with `{...} | dd` +test/data/err_173.py:34:5 [FURB173]: Replace `{..., **userdict}` with `{...} | userdict` test/data/err_173.py:37:5 [FURB173]: Replace `dict(**x)` with `{**x}` test/data/err_173.py:38:5 [FURB173]: Replace `dict(x, **y)` with `x | y` test/data/err_173.py:39:5 [FURB173]: Replace `dict(**x, **y)` with `x | y`