Skip to content

Commit 23a7bac

Browse files
authored
Merge branch 'main' into dependabot/github_actions/all-dependencies-1f777302ca
2 parents 2685f68 + c0ff08f commit 23a7bac

20 files changed

Lines changed: 143 additions & 134 deletions

ruff.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[lint]
2+
ignore = [
3+
"BLE001",
4+
"DTZ001",
5+
"EXE001",
6+
"FLY002",
7+
"N999",
8+
"RUF012",
9+
"S102",
10+
"SIM115",
11+
"TRY002",
12+
"UP031",
13+
]

setup.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import os
33
import subprocess
44
import sys
5-
6-
import setuptools
75
from configparser import ConfigParser
86

7+
import setuptools
98

109
release_info = {}
1110
with open("src/MySQLdb/release.py", encoding="utf-8") as f:
@@ -70,11 +69,11 @@ def get_config_posix(options=None):
7069
("__version__", release_info["__version__"]),
7170
]
7271

73-
ext_options = dict(
74-
extra_compile_args=cflags,
75-
extra_link_args=ldflags,
76-
define_macros=define_macros,
77-
)
72+
ext_options = {
73+
"extra_compile_args": cflags,
74+
"extra_link_args": ldflags,
75+
"define_macros": define_macros,
76+
}
7877
# newer versions of gcc require libstdc++ if doing a static build
7978
if static:
8079
ext_options["language"] = "c++"
@@ -120,14 +119,14 @@ def get_config_win32(options):
120119
("__version__", release_info["__version__"]),
121120
]
122121

123-
ext_options = dict(
124-
library_dirs=library_dirs,
125-
libraries=libraries,
126-
extra_link_args=extra_link_args,
127-
include_dirs=include_dirs,
128-
extra_objects=extra_objects,
129-
define_macros=define_macros,
130-
)
122+
ext_options = {
123+
"library_dirs": library_dirs,
124+
"libraries": libraries,
125+
"extra_link_args": extra_link_args,
126+
"include_dirs": include_dirs,
127+
"extra_objects": extra_objects,
128+
"define_macros": define_macros,
129+
}
131130
return ext_options
132131

133132

src/MySQLdb/__init__.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
MySQLdb.converters module.
1414
"""
1515

16-
from .release import version_info
1716
from . import _mysql
17+
from .release import version_info
1818

1919
if version_info != _mysql.version_info:
2020
raise ImportError(
@@ -24,32 +24,33 @@
2424
)
2525

2626

27-
from ._mysql import (
28-
NotSupportedError,
29-
OperationalError,
30-
get_client_info,
31-
ProgrammingError,
32-
Error,
33-
InterfaceError,
34-
debug,
35-
IntegrityError,
36-
string_literal,
37-
MySQLError,
38-
DataError,
39-
DatabaseError,
40-
InternalError,
41-
Warning,
42-
)
4327
from MySQLdb.constants import FIELD_TYPE
4428
from MySQLdb.times import (
4529
Date,
46-
Time,
47-
Timestamp,
4830
DateFromTicks,
31+
Time,
4932
TimeFromTicks,
33+
Timestamp,
5034
TimestampFromTicks,
5135
)
5236

37+
from ._mysql import (
38+
DatabaseError,
39+
DataError,
40+
Error,
41+
IntegrityError,
42+
InterfaceError,
43+
InternalError,
44+
MySQLError,
45+
NotSupportedError,
46+
OperationalError,
47+
ProgrammingError,
48+
Warning,
49+
debug,
50+
get_client_info,
51+
string_literal,
52+
)
53+
5354
threadsafety = 1
5455
apilevel = "2.0"
5556
paramstyle = "format"
@@ -95,7 +96,7 @@ def __eq__(self, other):
9596

9697

9798
def test_DBAPISet_set_equality():
98-
assert STRING == STRING
99+
assert STRING == STRING # noqa
99100

100101

101102
def test_DBAPISet_set_inequality():
@@ -125,33 +126,33 @@ def Connect(*args, **kwargs):
125126

126127
__all__ = [
127128
"BINARY",
129+
"DATE",
130+
"FIELD_TYPE",
131+
"NUMBER",
132+
"ROWID",
133+
"STRING",
134+
"TIME",
135+
"TIMESTAMP",
128136
"Binary",
129137
"Connect",
130138
"Connection",
131-
"DATE",
132-
"Date",
133-
"Time",
134-
"Timestamp",
135-
"DateFromTicks",
136-
"TimeFromTicks",
137-
"TimestampFromTicks",
139+
"DBAPISet",
138140
"DataError",
139141
"DatabaseError",
142+
"Date",
143+
"DateFromTicks",
140144
"Error",
141-
"FIELD_TYPE",
142145
"IntegrityError",
143146
"InterfaceError",
144147
"InternalError",
145148
"MySQLError",
146-
"NUMBER",
147149
"NotSupportedError",
148-
"DBAPISet",
149150
"OperationalError",
150151
"ProgrammingError",
151-
"ROWID",
152-
"STRING",
153-
"TIME",
154-
"TIMESTAMP",
152+
"Time",
153+
"TimeFromTicks",
154+
"Timestamp",
155+
"TimestampFromTicks",
155156
"Warning",
156157
"apilevel",
157158
"connect",

src/MySQLdb/connections.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77

88
import re
99

10-
from . import cursors, _mysql
10+
from . import _mysql, cursors
1111
from ._exceptions import (
12-
Warning,
13-
Error,
14-
InterfaceError,
15-
DataError,
1612
DatabaseError,
17-
OperationalError,
13+
DataError,
14+
Error,
1815
IntegrityError,
16+
InterfaceError,
1917
InternalError,
2018
NotSupportedError,
19+
OperationalError,
2120
ProgrammingError,
21+
Warning,
2222
)
2323

2424
# Mapping from MySQL charset name to Python codec name
@@ -164,7 +164,7 @@ class object, used to create cursors (keyword only)
164164
documentation for the MySQL C API for some hints on what they do.
165165
"""
166166
from MySQLdb.constants import CLIENT, FIELD_TYPE
167-
from MySQLdb.converters import conversions, _bytes_or_str
167+
from MySQLdb.converters import _bytes_or_str, conversions
168168

169169
kwargs2 = kwargs.copy()
170170

@@ -173,11 +173,7 @@ class object, used to create cursors (keyword only)
173173
if "passwd" in kwargs2:
174174
kwargs2["password"] = kwargs2.pop("passwd")
175175

176-
if "conv" in kwargs:
177-
conv = kwargs["conv"]
178-
else:
179-
conv = conversions
180-
176+
conv = kwargs.get("conv", conversions)
181177
conv2 = {}
182178
for k, v in conv.items():
183179
if isinstance(k, int) and isinstance(v, list):
@@ -207,11 +203,7 @@ class object, used to create cursors (keyword only)
207203
super().__init__(*args, **kwargs2)
208204

209205
self.cursorclass = cursorclass
210-
self.encoders = {
211-
k: v
212-
for k, v in conv.items()
213-
if type(k) is not int # noqa: E721
214-
}
206+
self.encoders = {k: v for k, v in conv.items() if type(k) is not int}
215207
self._server_version = tuple(
216208
[numeric_part(n) for n in self.get_server_info().split(".")[:2]]
217209
)
@@ -240,9 +232,8 @@ class object, used to create cursors (keyword only)
240232
self.converter[FIELD_TYPE.JSON] = str
241233

242234
self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS
243-
if self._transactional:
244-
if autocommit is not None:
245-
self.autocommit(autocommit)
235+
if self._transactional and autocommit is not None:
236+
self.autocommit(autocommit)
246237
self.messages = []
247238

248239
def _set_attributes(
@@ -314,9 +305,7 @@ def literal(self, o):
314305
"""
315306
if isinstance(o, str):
316307
s = self.string_literal(o.encode(self.encoding))
317-
elif isinstance(o, bytearray):
318-
s = self._bytes_literal(o)
319-
elif isinstance(o, bytes):
308+
elif isinstance(o, (bytes, bytearray)):
320309
s = self._bytes_literal(o)
321310
elif isinstance(o, (tuple, list)):
322311
s = self._tuple_literal(o)

src/MySQLdb/constants/ER.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
m = re.match(r"^\s*#define\s+((ER|WARN)_[A-Z0-9_]+)\s+(\d+)\s*", line)
1919
if m:
2020
name = m.group(1)
21-
if name.startswith("ER_"):
22-
name = name[3:]
21+
name = name.removeprefix("ER_")
2322
value = int(m.group(3))
2423
if name == "ERROR_LAST":
2524
if error_last is None or error_last < value:

src/MySQLdb/constants/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__all__ = ["CR", "FIELD_TYPE", "CLIENT", "ER", "FLAG"]
1+
__all__ = ["CLIENT", "CR", "ER", "FIELD_TYPE", "FLAG"]

src/MySQLdb/converters.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,22 @@
3131
MySQL.connect().
3232
"""
3333

34+
import array
3435
from decimal import Decimal
3536

37+
from MySQLdb._exceptions import ProgrammingError
3638
from MySQLdb._mysql import string_literal
3739
from MySQLdb.constants import FIELD_TYPE, FLAG
3840
from MySQLdb.times import (
3941
Date,
40-
DateTimeType,
42+
Date_or_None,
4143
DateTime2literal,
42-
DateTimeDeltaType,
43-
DateTimeDelta2literal,
4444
DateTime_or_None,
45+
DateTimeDelta2literal,
46+
DateTimeDeltaType,
47+
DateTimeType,
4548
TimeDelta_or_None,
46-
Date_or_None,
4749
)
48-
from MySQLdb._exceptions import ProgrammingError
49-
50-
import array
5150

5251
NoneType = type(None)
5352

src/MySQLdb/cursors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ def __getattr__(self, name):
345345
# DB-API 2.0 optional extension says these errors can be accessed
346346
# via Connection object. But MySQLdb had defined them on Cursor object.
347347
import warnings
348+
348349
from . import _exceptions as err
349350

350351
if name in (

src/MySQLdb/times.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
Use Python datetime module to handle date and time columns.
66
"""
77

8-
from time import localtime
98
from datetime import date, datetime, time, timedelta
9+
from time import localtime
10+
1011
from MySQLdb._mysql import string_literal
1112

1213
Date = date

tests/capabilities.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
77
"""
88

9-
from time import time
109
import unittest
10+
from time import time
11+
1112
from configdb import connection_factory
1213

1314

1415
class DatabaseTest(unittest.TestCase):
1516
db_module = None
1617
connect_args = ()
17-
connect_kwargs = dict()
18+
connect_kwargs = {}
1819
create_table_extra = ""
1920
rows = 10
2021
debug = False
@@ -162,7 +163,7 @@ def generator(row, col):
162163
pass
163164
else:
164165
self.fail(
165-
"Over-long column did not generate warnings/exception with single insert" # noqa: E501
166+
"Over-long column did not generate warnings/exception with single insert"
166167
)
167168

168169
self.connection.rollback()
@@ -177,7 +178,7 @@ def generator(row, col):
177178
pass
178179
else:
179180
self.fail(
180-
"Over-long columns did not generate warnings/exception with execute()" # noqa: E501
181+
"Over-long columns did not generate warnings/exception with execute()"
181182
)
182183

183184
self.connection.rollback()
@@ -192,7 +193,7 @@ def generator(row, col):
192193
pass
193194
else:
194195
self.fail(
195-
"Over-long columns did not generate warnings/exception with executemany()" # noqa: E501
196+
"Over-long columns did not generate warnings/exception with executemany()"
196197
)
197198

198199
self.connection.rollback()

0 commit comments

Comments
 (0)