Skip to content

Commit

Permalink
Rerun with updated Ruff and remove UP031 exclusion for adodbapi
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Jun 1, 2024
1 parent 86defcb commit 5532e4d
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 147 deletions.
28 changes: 14 additions & 14 deletions adodbapi/adodbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def connect(*args, **kwargs): # --> a db-api connection object
co.connect(kwargs)
return co
except Exception as e:
message = 'Error opening connection to "%s"' % co.connection_string
message = f'Error opening connection to "{co.connection_string}"'
raise api.OperationalError(e, message)


Expand Down Expand Up @@ -265,7 +265,7 @@ def connect(self, kwargs, connection_maker=make_COM_connecter):
except api.Error:
self._raiseConnectionError(
api.DatabaseError,
"ADO error trying to Open=%s" % self.connection_string,
f"ADO error trying to Open={self.connection_string}",
)

try: # Stefan Fuchs; support WINCCOLEDBProvider
Expand Down Expand Up @@ -294,7 +294,7 @@ def connect(self, kwargs, connection_maker=make_COM_connecter):
self.paramstyle = kwargs["paramstyle"] # let setattr do the error checking
self.messages = []
if verbose:
print("adodbapi New connection at %X" % id(self))
print(f"adodbapi New connection at {id(self):X}")

def _raiseConnectionError(self, errorclass, errorvalue):
eh = self.errorhandler
Expand All @@ -315,7 +315,7 @@ def _closeAdoConnection(self): # all v2.1 Rose
pass
self.connector.Close()
if verbose:
print("adodbapi Closed connection at %X" % id(self))
print(f"adodbapi Closed connection at {id(self):X}")

def close(self):
"""Close the connection now (rather than whenever __del__ is called).
Expand Down Expand Up @@ -352,7 +352,7 @@ def commit(self):
try:
self.transaction_level = self.connector.CommitTrans()
if verbose > 1:
print("commit done on connection at %X" % id(self))
print(f"commit done on connection at {id(self):X}")
if not (
self._autocommit
or (self.connector.Attributes & adc.adXactAbortRetaining)
Expand Down Expand Up @@ -386,7 +386,7 @@ def _rollback(self):
try:
self.transaction_level = self.connector.RollbackTrans()
if verbose > 1:
print("rollback done on connection at %X" % id(self))
print(f"rollback done on connection at {id(self):X}")
if not self._autocommit and not (
self.connector.Attributes & adc.adXactAbortRetaining
):
Expand Down Expand Up @@ -435,7 +435,7 @@ def __getattr__(self, item):
return self._autocommit
else:
raise AttributeError(
'no such attribute in ADO connection object as="%s"' % item
f'no such attribute in ADO connection object as="{item}"'
)

def cursor(self):
Expand All @@ -461,17 +461,17 @@ def printADOerrors(self):
if j:
print("ADO Errors:(%i)" % j)
for e in self.connector.Errors:
print("Description: %s" % e.Description)
print(f"Description: {e.Description}")
print(
"Error: {} {} ".format(e.Number, adc.adoErrors.get(e.Number, "unknown"))
)
if e.Number == adc.ado_error_TIMEOUT:
print(
"Timeout Error: Try using adodbpi.connect(constr,timeout=Nseconds)"
)
print("Source: %s" % e.Source)
print("NativeError: %s" % e.NativeError)
print("SQL State: %s" % e.SQLState)
print(f"Source: {e.Source}")
print(f"NativeError: {e.NativeError}")
print(f"SQL State: {e.SQLState}")

def _suggest_error_class(self):
"""Introspect the current ADO Errors and determine an appropriate error class.
Expand Down Expand Up @@ -619,7 +619,7 @@ def build_column_info(self, recordset):
) # conversion function for this column
except KeyError:
self._raiseCursorError(
api.InternalError, "Data column of Unknown ADO type=%s" % f.Type
api.InternalError, f"Data column of Unknown ADO type={f.Type}"
)
self.columnNames[f.Name.lower()] = i # columnNames lookup

Expand Down Expand Up @@ -701,7 +701,7 @@ def close(self, dont_tell_me=False):
None # this will make all future method calls on me throw an exception
)
if verbose:
print("adodbapi Closed cursor at %X" % id(self))
print(f"adodbapi Closed cursor at {id(self):X}")

def __del__(self):
try:
Expand Down Expand Up @@ -735,7 +735,7 @@ def _execute_command(self):
recordset = None
count = -1 # default value
if verbose:
print('Executing command="%s"' % self.commandText)
print(f'Executing command="{self.commandText}"')
try:
# ----- the actual SQL is executed here ---
recordset, count = self.cmd.Execute()
Expand Down
2 changes: 1 addition & 1 deletion adodbapi/apibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ def changeFormatToQmark(
s, chunk = sp[1].split(")s", 1) # find the ')s'
except ValueError:
raise ProgrammingError(
'Pyformat SQL has incorrect format near "%s"' % chunk
f'Pyformat SQL has incorrect format near "{chunk}"'
)
outparams.append(s)
outOp += "?" # put in the Qmark
Expand Down
4 changes: 2 additions & 2 deletions adodbapi/examples/db_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
# make a cursor on the connection
with con.cursor() as c:
# run an SQL statement on the cursor
sql = "select * from %s" % kw_args["table_name"]
print('performing query="%s"' % sql)
sql = "select * from {}".format(kw_args["table_name"])
print(f'performing query="{sql}"')
c.execute(sql)

# check the results
Expand Down
2 changes: 1 addition & 1 deletion adodbapi/examples/db_table_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# create the connection
con = adodbapi.connect(constr, db=databasename, macro_is64bit=provider)

print("Table names in= %s" % databasename)
print(f"Table names in= {databasename}")

for table in con.get_table_names():
print(table)
2 changes: 1 addition & 1 deletion adodbapi/examples/xls_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
print(f"Shreadsheet={filename} Worksheet={sheet}")
print("------------------------------------------------------------")
crsr = conn.cursor()
sql = "SELECT * from [%s]" % sheet
sql = f"SELECT * from [{sheet}]"
crsr.execute(sql)
for row in crsr.fetchmany(10):
print(repr(row))
Expand Down
2 changes: 1 addition & 1 deletion adodbapi/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
for line in a:
if "__version__" in line:
VERSION = line.split("'")[1]
print('adodbapi version="%s"' % VERSION)
print(f'adodbapi version="{VERSION}"')
break
a.close()

Expand Down
Loading

0 comments on commit 5532e4d

Please sign in to comment.