Skip to content

Commit 1eb8798

Browse files
committed
Fix linting issues detected by the latest pylint version
Change-Id: I54bd251f47c65f082dce9687214b3f7c4b93ac25
1 parent 4e8aaed commit 1eb8798

File tree

9 files changed

+27
-36
lines changed

9 files changed

+27
-36
lines changed

lib/mysql/connector/connection_cext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@
7979
CMySQLCursorPreparedRaw,
8080
CMySQLCursorRaw,
8181
)
82+
83+
HAVE_CMYSQL = True
8284
except ImportError as exc:
8385
raise ImportError(
8486
f"MySQL Connector/Python C Extension not available ({exc})"
8587
) from exc
86-
else:
87-
HAVE_CMYSQL = True
8888

8989

9090
class CMySQLConnection(MySQLConnectionAbstract):

lib/mysql/connector/constants.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,10 @@ def get_default_collation(cls, charset: Union[int, str]) -> Tuple[str, str, int]
776776
try:
777777
info = cls.desc[charset]
778778
return info[1], info[0], charset
779-
except (IndexError, KeyError):
780-
ProgrammingError(f"Character set ID '{charset}' unsupported")
779+
except (IndexError, KeyError) as err:
780+
raise ProgrammingError(
781+
f"Character set ID '{charset}' unsupported"
782+
) from err
781783

782784
for cid, info in enumerate(cls.desc):
783785
if info is None:
@@ -811,8 +813,8 @@ def get_charset_info(
811813
try:
812814
info = cls.desc[charset]
813815
return (charset, info[0], info[1])
814-
except IndexError:
815-
ProgrammingError(f"Character set ID {charset} unknown")
816+
except IndexError as err:
817+
raise ProgrammingError(f"Character set ID {charset} unknown") from err
816818

817819
if charset in ("utf8", "utf-8") and cls.mysql_version == (8, 0):
818820
charset = "utf8mb4"

lib/mysql/connector/cursor.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,11 @@ def _process_params_dict(
434434
self, params: ParamsDictType
435435
) -> Dict[bytes, Union[bytes, Decimal]]:
436436
"""Process query parameters given as dictionary"""
437+
res: Dict[bytes, Any] = {}
437438
try:
438439
to_mysql = self._connection.converter.to_mysql
439440
escape = self._connection.converter.escape
440441
quote = self._connection.converter.quote
441-
res: Dict[bytes, Any] = {}
442442
for key, value in params.items():
443443
conv = value
444444
conv = to_mysql(conv)
@@ -450,20 +450,17 @@ def _process_params_dict(
450450
raise ProgrammingError(
451451
f"Failed processing pyformat-parameters; {err}"
452452
) from err
453-
else:
454-
return res
453+
return res
455454

456455
def _process_params(
457456
self, params: ParamsSequenceType
458457
) -> Tuple[Union[bytes, Decimal], ...]:
459458
"""Process query parameters."""
459+
res = params[:]
460460
try:
461-
res = params[:]
462-
463461
to_mysql = self._connection.converter.to_mysql
464462
escape = self._connection.converter.escape
465463
quote = self._connection.converter.quote
466-
467464
res = [to_mysql(value) for value in res]
468465
res = [escape(value) for value in res]
469466
res = [
@@ -474,8 +471,7 @@ def _process_params(
474471
raise ProgrammingError(
475472
f"Failed processing format-parameters; {err}"
476473
) from err
477-
else:
478-
return tuple(res)
474+
return tuple(res)
479475

480476
def _handle_noresultset(self, res: ResultType) -> None:
481477
"""Handles result of execute() when there is no result set"""
@@ -1094,10 +1090,8 @@ def _fetch_row(self, raw: bool = False) -> Optional[RowType]:
10941090
row = self._rows[self._next_row]
10951091
except (IndexError, TypeError):
10961092
return None
1097-
else:
1098-
self._next_row += 1
1099-
return row
1100-
return None
1093+
self._next_row += 1
1094+
return row
11011095

11021096
def fetchone(self) -> Optional[RowType]:
11031097
"""Return next row of a query result set.

lib/mysql/connector/cursor_cext.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,7 @@ def _fetch_row(self) -> Optional[RowType]:
806806
row = self._rows[self._next_row]
807807
except IndexError:
808808
return None
809-
else:
810-
self._next_row += 1
811-
809+
self._next_row += 1
812810
return row
813811

814812
def fetchall(self) -> List[RowType]:

lib/mysql/connector/django/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
1+
# Copyright (c) 2020, 2023, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -515,8 +515,7 @@ def is_usable(self) -> bool:
515515
self.connection.ping()
516516
except Error:
517517
return False
518-
else:
519-
return True
518+
return True
520519

521520
@cached_property
522521
@staticmethod

lib/mysql/connector/errors.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2009, 2022, Oracle and/or its affiliates.
1+
# Copyright (c) 2009, 2023, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -287,8 +287,7 @@ def get_exception(packet: bytes) -> ErrorTypes:
287287
errmsg = packet.decode("utf8")
288288
except (IndexError, UnicodeError) as err:
289289
return InterfaceError(f"Failed getting Error information ({err})")
290-
else:
291-
return get_mysql_exception(errno, errmsg, sqlstate) # type: ignore[arg-type]
290+
return get_mysql_exception(errno, errmsg, sqlstate)
292291

293292

294293
_SQLSTATE_CLASS_EXCEPTION: Dict[str, ErrorClassTypes] = {

lib/mysql/connector/network.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2012, 2022, Oracle and/or its affiliates.
1+
# Copyright (c) 2012, 2023, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -590,8 +590,8 @@ def open_connection(self) -> None:
590590
raise InterfaceError(
591591
errno=2003, values=(self.get_address(), _strioerror(err))
592592
) from err
593-
else:
594-
(self._family, socktype, proto, _, sockaddr) = addrinfo
593+
594+
(self._family, socktype, proto, _, sockaddr) = addrinfo
595595

596596
# Instanciate the socket and connect
597597
try:

lib/mysqlx/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2022, Oracle and/or its affiliates.
1+
# Copyright (c) 2016, 2023, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -1687,8 +1687,8 @@ def queue_connection(self, cnx: PooledConnection) -> None:
16871687
cnx.reset_session()
16881688
try:
16891689
self.put(cnx, block=False)
1690-
except queue.Full:
1691-
PoolError("Failed adding connection; queue is full")
1690+
except queue.Full as err:
1691+
raise PoolError("Failed adding connection; queue is full") from err
16921692

16931693
def track_connection(self, connection: PooledConnection) -> None:
16941694
"""Tracks connection in order of close it when client.close() is invoke."""

lib/mysqlx/errors.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2022, Oracle and/or its affiliates.
1+
# Copyright (c) 2016, 2023, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -209,8 +209,7 @@ def get_exception(packet: bytes) -> ErrorTypes:
209209
errmsg = packet.decode("utf8")
210210
except (IndexError, ValueError) as err:
211211
return InterfaceError(f"Failed getting Error information ({err})")
212-
else:
213-
return get_mysql_exception(errno, errmsg, sqlstate) # type: ignore[arg-type]
212+
return get_mysql_exception(errno, errmsg, sqlstate)
214213

215214

216215
_SQLSTATE_CLASS_EXCEPTION: Dict[str, ErrorClassTypes] = {

0 commit comments

Comments
 (0)