Skip to content

Maintenance: apply refurb fixes and tighten ruff#671

Merged
penguinolog merged 1 commit into
urwid:masterfrom
penguinolog:maintenance_code_quality
Nov 16, 2023
Merged

Maintenance: apply refurb fixes and tighten ruff#671
penguinolog merged 1 commit into
urwid:masterfrom
penguinolog:maintenance_code_quality

Conversation

@penguinolog

Copy link
Copy Markdown
Collaborator
Checklist
  • I've ensured that similar functionality has not already been implemented
  • I've ensured that similar functionality has not earlier been proposed and declined
  • I've branched off the master or python-dual-support branch
  • I've merged fresh upstream into my branch recently
  • I've ran tox successfully in local environment
  • I've included docstrings and/or documentation and/or examples for my code (if this is a new feature)

Comment thread examples/calc.py
if key == "backspace":
raise ColumnDeleteEvent(self.letter, from_parent=True)
if key in list("0123456789"):
if key in string.digits:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can iterate over string directly without cast
we can use stdlib human-readable constant instead of copy-paste

Comment thread examples/calc.py
"+": (lambda a, b: a + b),
"-": (lambda a, b: a - b),
"*": (lambda a, b: a * b),
"+": operator.add,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have stdlib fuctions (mostly used by data engineers)

@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 6888615993

  • 20 of 29 (68.97%) changed or added relevant lines in 12 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 74.156%

Changes Missing Coverage Covered Lines Changed/Added Lines %
urwid/treetools.py 0 1 0.0%
urwid/escape.py 0 2 0.0%
urwid/display_common.py 0 3 0.0%
urwid/raw_display.py 1 4 25.0%
Totals Coverage Status
Change from base Build 6799398569: -0.2%
Covered Lines: 7515
Relevant Lines: 10277

💛 - Coveralls

Comment thread examples/palette_test.py
"""
out = []
for match in re.finditer(ATTR_RE, chart):
for match in ATTR_RE.finditer(chart):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compiled regex do not require re-compilation

Comment thread urwid/display_common.py
return None

c256 = _parse_color_256("#" + "".join(format(int(x, 16) // 16, "x") for x in [desc[1:3], desc[3:5], desc[5:7]]))
c256 = _parse_color_256("#" + "".join(format(int(x, 16) // 16, "x") for x in (desc[1:3], desc[3:5], desc[5:7])))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommended to use temporary tuples instead of temporary lists

Comment thread urwid/escape.py
for digit, key in zip("235678", ("insert", "delete", "page up", "page down", "home", "end"))
),
*((f"O{chr(ord('p') + n)}", str(n)) for n in range(10)),
*((f"O{ord('p') + n:c}", str(n)) for n in range(10)),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:c command execute chr internally during string formatting

Comment thread urwid/treetools.py

def get_depth(self):
if self._depth is None and self._parent is None:
if self._depth is self._parent is None:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... is ... is ... is recommended (and should be faster than or)

@penguinolog penguinolog requested review from ulidtko and wardi November 16, 2023 17:03
@penguinolog penguinolog merged commit 1f7560a into urwid:master Nov 16, 2023
@penguinolog penguinolog deleted the maintenance_code_quality branch November 16, 2023 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants