Skip to content

Commit cd76dcb

Browse files
authored
fully-qualify pymysql exception classes in main.py (#1421)
as in sqlexecute.py. It is otherwise not clear from a casual glance that something like "err.InterfaceError" derives from pymysql.
1 parent f38ea17 commit cd76dcb

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Internal
1717
--------
1818
* Refine documentation for Windows.
1919
* Target Python 3.10 for linting.
20+
* Use fully-qualified pymysql exception classes.
2021

2122

2223
1.42.0 (2025/12/20)

mycli/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from prompt_toolkit.layout.processors import ConditionalProcessor, HighlightMatchingBracketProcessor
3838
from prompt_toolkit.lexers import PygmentsLexer
3939
from prompt_toolkit.shortcuts import CompleteStyle, PromptSession
40-
from pymysql import OperationalError, err
40+
import pymysql
4141
from pymysql.cursors import Cursor
4242
import sqlglot
4343
import sqlparse
@@ -532,7 +532,7 @@ def _connect() -> None:
532532
ssh_key_filename,
533533
init_command,
534534
)
535-
except OperationalError as e:
535+
except pymysql.OperationalError as e:
536536
if e.args[0] == ERROR_CODE_ACCESS_DENIED:
537537
if password_from_file is not None:
538538
new_passwd = password_from_file
@@ -566,7 +566,7 @@ def _connect() -> None:
566566
self.echo(f"Connecting to socket {socket}, owned by user {socket_owner}", err=True)
567567
try:
568568
_connect()
569-
except OperationalError as e:
569+
except pymysql.OperationalError as e:
570570
# These are "Can't open socket" and 2x "Can't connect"
571571
if [code for code in (2001, 2002, 2003) if code == e.args[0]]:
572572
self.logger.debug("Database connection failed: %r.", e)
@@ -919,7 +919,7 @@ def one_iteration(text: str | None = None) -> None:
919919
output_res(res, start)
920920
special.unset_once_if_written(self.post_redirect_command)
921921
special.flush_pipe_once_if_written(self.post_redirect_command)
922-
except err.InterfaceError:
922+
except pymysql.err.InterfaceError:
923923
# attempt to reconnect
924924
if not self.reconnect():
925925
return
@@ -955,7 +955,7 @@ def one_iteration(text: str | None = None) -> None:
955955
self.echo("Did not get a connection id, skip cancelling query", err=True, fg="red")
956956
except NotImplementedError:
957957
self.echo("Not Yet Implemented.", fg="yellow")
958-
except OperationalError as e1:
958+
except pymysql.OperationalError as e1:
959959
logger.debug("Exception: %r", e1)
960960
if e1.args[0] in (2003, 2006, 2013):
961961
# attempt to reconnect
@@ -1044,7 +1044,7 @@ def reconnect(self, database: str = "") -> bool:
10441044
self.echo("Reconnecting...", fg="yellow")
10451045
try:
10461046
self.sqlexecute.connect()
1047-
except OperationalError as e:
1047+
except pymysql.OperationalError as e:
10481048
self.logger.debug("Reconnect failed. e: %r", e)
10491049
self.echo(str(e), err=True, fg="red")
10501050
return False

0 commit comments

Comments
 (0)