Skip to content

Commit

Permalink
Improve error messages for FURB173, bump version for release
Browse files Browse the repository at this point in the history
  • Loading branch information
dosisod committed Jan 8, 2024
1 parent 5986070 commit d583934
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 4 additions & 7 deletions refurb/checks/readability/use_dict_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,17 @@ 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

else:
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}`"

Expand Down
32 changes: 16 additions & 16 deletions test/data/err_173.txt
Original file line number Diff line number Diff line change
@@ -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`
Expand Down

0 comments on commit d583934

Please sign in to comment.