Skip to content

Add Refurb to ruff#87

Closed
Fokko wants to merge 1 commit intoapache:mainfrom
Fokko:fd-add-refurb
Closed

Add Refurb to ruff#87
Fokko wants to merge 1 commit intoapache:mainfrom
Fokko:fd-add-refurb

Conversation

@Fokko
Copy link
Copy Markdown
Contributor

@Fokko Fokko commented Oct 19, 2023

Seems to do some nice checks:
https://docs.astral.sh/ruff/rules/#refurb-furb

@jayceslesar
Copy link
Copy Markdown
Contributor

You might want to have a config here that enables and disables certain checks but that can come with trial and error

@Fokko
Copy link
Copy Markdown
Contributor Author

Fokko commented Oct 19, 2023

@jayceslesar Thanks for chiming in here. I believe that all checks are enabled when the plugin is enabled. In the current codebase, there are no violations. Enabling this will make sure that we don't violate the checks in the future. Or did I miss something? #86 shows some changes that were corrected by adding flake8-pie

@jayceslesar
Copy link
Copy Markdown
Contributor

@Fokko running the latest version of refurb:

refurb pyiceberg
pyiceberg/avro/encoder.py:40:31 [FURB123]: Replace `bool(x)` with `x`
pyiceberg/avro/reader.py:354:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/avro/writer.py:188:12 [FURB115]: Replace `len(x) > 0` with `x`
pyiceberg/avro/writer.py:202:12 [FURB115]: Replace `len(x) > 0` with `x`
pyiceberg/catalog/__init__.py:582:30 [FURB123]: Replace `dict(x)` with `x.copy()`
pyiceberg/catalog/dynamodb.py:342:12 [FURB115]: Replace `len(x) > 0` with `x`
pyiceberg/catalog/dynamodb.py:588:28 [FURB130]: Replace `not in d.keys()` with `not in d`
pyiceberg/catalog/glue.py:386:12 [FURB115]: Replace `len(x) > 0` with `x`
pyiceberg/catalog/hive.py:213:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/catalog/sql.py:360:29 [FURB110]: Replace `x if x else y` with `x or y`
pyiceberg/cli/console.py:116:43 [FURB115]: Replace `len(x) > 0` with `x`
pyiceberg/cli/console.py:135:8 [FURB124]: Replace `x is y and z is y` with `x is y is z`
pyiceberg/cli/console.py:135:8 [FURB149]: Replace `x is False` with `not x`
pyiceberg/cli/console.py:135:34 [FURB149]: Replace `x is False` with `not x`
pyiceberg/conversions.py:258:20 [FURB123]: Replace `int(x)` with `x`
pyiceberg/conversions.py:277:21 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/conversions.py:311:12 [FURB123]: Replace `bytes(x)` with `x`
pyiceberg/expressions/__init__.py:57:9 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/expressions/__init__.py:135:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:135:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:166:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:221:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:221:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:225:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:225:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:264:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:264:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:294:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:386:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:386:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:397:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:397:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:525:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:525:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:530:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:530:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:561:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:561:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:566:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:566:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:590:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/expressions/__init__.py:617:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/expressions/__init__.py:639:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/expressions/__init__.py:661:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/expressions/__init__.py:710:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:710:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:710:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:734:16 [FURB119]: Replace `{str(x)}` with `{x}`
pyiceberg/expressions/__init__.py:734:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/__init__.py:734:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/literals.py:150:25 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/literals.py:285:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/expressions/literals.py:488:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/expressions/literals.py:498:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/expressions/literals.py:508:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/expressions/literals.py:591:27 [FURB109]: Replace `in [x, y, z]` with `in (x, y, z)`
pyiceberg/expressions/literals.py:598:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/expressions/parser.py:100:9 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/io/pyarrow.py:315:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/io/pyarrow.py:788:20 [FURB108]: Replace `x == y or x == z` with `x in (y, z)`
pyiceberg/io/pyarrow.py:888:8 [FURB115]: Replace `len(x) > 0` with `x`
pyiceberg/io/pyarrow.py:1286:40 [FURB121]: Replace `isinstance(x, y) or isinstance(x, z)` with `isinstance(x, y | z)`
pyiceberg/io/pyarrow.py:1293:47 [FURB109]: Replace `in [x, y, z]` with `in (x, y, z)`
pyiceberg/io/pyarrow.py:1515:9 [FURB131]: Replace `del x[y]` with `x.pop(y)`
pyiceberg/io/pyarrow.py:1516:9 [FURB131]: Replace `del x[y]` with `x.pop(y)`
pyiceberg/io/pyarrow.py:1517:9 [FURB131]: Replace `del x[y]` with `x.pop(y)`
pyiceberg/manifest.py:653:14 [FURB108]: Replace `x == y or x == z` with `x in (y, z)`
pyiceberg/manifest.py:790:9 [FURB125]: Return is redundant here
pyiceberg/partitioning.py:107:30 [FURB123]: Replace `tuple(x)` with `x`
pyiceberg/schema.py:1122:9 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/schema.py:1329:56 [FURB149]: Replace `x is True` with `x`
pyiceberg/schema.py:1404:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/schema.py:1411:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/schema.py:1420:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/table/__init__.py:235:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/table/__init__.py:748:9 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/table/__init__.py:1024:12 [FURB115]: Replace `len(x) > 0` with `x`
pyiceberg/table/__init__.py:1038:9 [FURB107]: Replace `try: ... except ValueError: pass` with `with suppress(ValueError): ...`
pyiceberg/table/__init__.py:1197:12 [FURB124]: Replace `x is y and z is y` with `x is y is z`
pyiceberg/table/__init__.py:1197:35 [FURB124]: Replace `x is y and z is y` with `x is y is z`
pyiceberg/table/__init__.py:1238:9 [FURB107]: Replace `try: ... except ValueError: pass` with `with suppress(ValueError): ...`
pyiceberg/table/__init__.py:1251:16 [FURB108]: Replace `x == y or x == z` with `x in (y, z)`
pyiceberg/table/__init__.py:1261:16 [FURB108]: Replace `x == y or x == z` with `x in (y, z)`
pyiceberg/table/__init__.py:1543:14 [FURB108]: Replace `x == y or x == z` with `x in (y, z)`
pyiceberg/table/__init__.py:1559:8 [FURB115]: Replace `len(x) > 0` with `x`
pyiceberg/table/__init__.py:1562:12 [FURB115]: Replace `len(x) > 0` with `x`
pyiceberg/table/__init__.py:1566:10 [FURB115]: Replace `len(x) > 0` with `x`
pyiceberg/table/__init__.py:1568:20 [FURB115]: Replace `len(x) == 0` with `not x`
pyiceberg/table/snapshots.py:81:27 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/table/snapshots.py:82:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/table/sorting.py:121:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/transforms.py:154:5 [FURB118]: Replace function with `operator.eq`
pyiceberg/transforms.py:220:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/transforms.py:310:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/transforms.py:658:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/transforms.py:736:16 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/transforms.py:783:9 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/transforms.py:802:9 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/typedef.py:195:55 [FURB119]: Replace `{repr(x)}` with `{x!r}`
pyiceberg/types.py:82:9 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/utils/bin_packing.py:106:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/utils/config.py:78:20 [FURB146]: Replace `os.path.isfile(x)` with `Path(x).is_file()`
pyiceberg/utils/config.py:79:21 [FURB101]: Replace `with open(x, ...) as f: y = f.read()` with `y = Path(x).read_text(...)`
pyiceberg/utils/config.py:107:19 [FURB115]: Replace `len(x) > 0` with `x`
pyiceberg/utils/config.py:109:20 [FURB115]: Replace `len(x) == 0` with `not x`
pyiceberg/utils/schema_conversion.py:554:13 [FURB126]: Replace `else: return x` with `return x`
pyiceberg/utils/singleton.py:45:21 [FURB123]: Replace `tuple(x)` with `x`
pyiceberg/utils/truncate.py:26:13 [FURB107]: Replace `try: ... except ValueError: pass` with `with suppress(ValueError): ...`

Run `refurb --explain ERR` to further explain an error. Use `--quiet` to silence this message

@Fokko
Copy link
Copy Markdown
Contributor Author

Fokko commented Oct 23, 2023

@jayceslesar It looks like that the ruff checker does not implement all the rules. Are you interested in adding Refurb directly?

@Fokko Fokko closed this Oct 23, 2023
@jayceslesar
Copy link
Copy Markdown
Contributor

@Fokko I am definitely interested in adding it directly! Can look into this next week

@Fokko Fokko deleted the fd-add-refurb branch October 24, 2023 13:54
@Fokko
Copy link
Copy Markdown
Contributor Author

Fokko commented Oct 24, 2023

@jayceslesar Thanks, there is no rush, appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants