Skip to content

Commit dba4f63

Browse files
committed
Ruff fixes.
1 parent 02d36a8 commit dba4f63

10 files changed

Lines changed: 63 additions & 67 deletions

File tree

pgcli/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ def register_special_commands(self):
315315
aliases=("use", "\\connect", "USE"),
316316
)
317317

318-
refresh_callback = lambda: self.refresh_completions(persist_priorities="all")
318+
def refresh_callback():
319+
return self.refresh_completions(persist_priorities="all")
319320

320321
self.pgspecial.register(
321322
self.quit,
@@ -439,7 +440,7 @@ def change_db(self, pattern, **_):
439440
# Get all the parameters in pattern, handling double quotes if any.
440441
infos = re.findall(r'"[^"]*"|[^"\'\s]+', pattern)
441442
# Now removing quotes.
442-
list(map(lambda s: s.strip('"'), infos))
443+
[s.strip('"') for s in infos]
443444

444445
infos.extend([None] * (4 - len(infos)))
445446
db, user, host, port = infos

pgcli/packages/parseutils/ctes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def isolate_query_ctes(full_text, text_before_cursor):
1717
"""Simplify a query by converting CTEs into table metadata objects"""
1818

1919
if not full_text or not full_text.strip():
20-
return full_text, text_before_cursor, tuple()
20+
return full_text, text_before_cursor, ()
2121

2222
ctes, remainder = extract_ctes(full_text)
2323
if not ctes:

pgcli/packages/sqlcompletion.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@
2626

2727
Function = namedtuple("Function", ["schema", "table_refs", "usage"])
2828
# For convenience, don't require the `usage` argument in Function constructor
29-
Function.__new__.__defaults__ = (None, tuple(), None)
30-
Table.__new__.__defaults__ = (None, tuple(), tuple())
31-
View.__new__.__defaults__ = (None, tuple())
32-
FromClauseItem.__new__.__defaults__ = (None, tuple(), tuple())
29+
Function.__new__.__defaults__ = (None, (), None)
30+
Table.__new__.__defaults__ = (None, (), ())
31+
View.__new__.__defaults__ = (None, ())
32+
FromClauseItem.__new__.__defaults__ = (None, (), ())
3333

3434
Column = namedtuple(
3535
"Column",
3636
["table_refs", "require_last_table", "local_tables", "qualifiable", "context"],
3737
)
38-
Column.__new__.__defaults__ = (None, None, tuple(), False, None)
38+
Column.__new__.__defaults__ = (None, None, (), False, None)
3939

4040
Keyword = namedtuple("Keyword", ["last_token"])
4141
Keyword.__new__.__defaults__ = (None,)
@@ -424,7 +424,7 @@ def suggest_based_on_last_token(token, stmt):
424424

425425
except ValueError:
426426
pass
427-
return tuple()
427+
return ()
428428

429429
elif token_v in ("table", "view"):
430430
# E.g. 'ALTER TABLE <tablname>'

pgcli/pgbuffer.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,7 @@ def cond():
4848
text = doc.text.strip()
4949

5050
return (
51-
text.startswith("\\") # Special Command
52-
or text.endswith(r"\e") # Special Command
53-
or text.endswith(r"\G") # Ended with \e which should launch the editor
54-
or _is_complete(text) # A complete SQL command
55-
or (text == "exit") # Exit doesn't need semi-colon
56-
or (text == "quit") # Quit doesn't need semi-colon
57-
or (text == ":q") # To all the vim fans out there
58-
or (text == "") # Just a plain enter without any text
51+
text.startswith("\\") or text.endswith((r"\e", r"\G")) or _is_complete(text) or text == "exit" or text == "quit" or text == ":q" or text == "" # Just a plain enter without any text
5952
)
6053

6154
return cond

pgcli/pgcompleter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def Candidate(completion, prio=None, meta=None, synonyms=None, prio2=None, displ
5454
# Used to strip trailing '::some_type' from default-value expressions
5555
arg_default_type_strip_regex = re.compile(r"::[\w\.]+(\[\])?$")
5656

57-
normalize_ref = lambda ref: ref if ref[0] == '"' else '"' + ref.lower() + '"'
57+
def normalize_ref(ref):
58+
return ref if ref[0] == '"' else '"' + ref.lower() + '"'
5859

5960

6061
def generate_alias(tbl, alias_map=None):
@@ -492,7 +493,8 @@ def get_column_matches(self, suggestion, word_before_cursor):
492493
"if_more_than_one_table": len(tables) > 1,
493494
}[self.qualify_columns]
494495
)
495-
qualify = lambda col, tbl: ((tbl + "." + self.case(col)) if do_qualify else self.case(col))
496+
def qualify(col, tbl):
497+
return ((tbl + "." + self.case(col)) if do_qualify else self.case(col))
496498
_logger.debug("Completion column scope: %r", tables)
497499
scoped_cols = self.populate_scoped_cols(tables, suggestion.local_tables)
498500

tests/formatter/test_sqlformatter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_output_sql_insert():
5555
}
5656
formatter.query = 'SELECT * FROM "user";'
5757
output = adapter(data, header, table_format=table_format, **kwargs)
58-
output_list = [l for l in output]
58+
output_list = list(output)
5959
expected = [
6060
'INSERT INTO "user" ("id", "name", "email", "phone", "description", "created_at", "updated_at") VALUES',
6161
" ('1', 'Jackson', 'jackson_test@gmail.com', '132454789', NULL, "
@@ -96,7 +96,7 @@ def test_output_sql_update():
9696
}
9797
formatter.query = 'SELECT * FROM "user";'
9898
output = adapter(data, header, table_format=table_format, **kwargs)
99-
output_list = [l for l in output]
99+
output_list = list(output)
100100
print(output_list)
101101
expected = [
102102
'UPDATE "user" SET',

tests/parseutils/test_parseutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_subselect_tables():
172172
@pytest.mark.parametrize("text", ["SELECT * FROM foo.", "SELECT 123 AS foo"])
173173
def test_extract_no_tables(text):
174174
tables = extract_tables(text)
175-
assert tables == tuple()
175+
assert tables == ()
176176

177177

178178
@pytest.mark.parametrize("arg_list", ["", "arg1", "arg1, arg2, arg3"])

tests/test_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def test_pset_pager_on(term_height, term_width, text, use_pager, pset_pager_mock
338338
],
339339
)
340340
def test_color_pattern(text, expected_length, pset_pager_mocks):
341-
cli = pset_pager_mocks[0]
341+
pset_pager_mocks[0]
342342
assert len(COLOR_CODE_REGEX.sub("", text)) == expected_length
343343

344344

0 commit comments

Comments
 (0)