Skip to content

Commit 3ba0865

Browse files
ckoehnrafiss
authored andcommitted
Use Python 3 syntax
Python 2 support has been dropped since 1.3.0 which allows us to use some of the new language features. The automatic update has been conducted with https://github.com/asottile/pyupgrade: pyupgrade --py36-plus <FILES>
1 parent 1786a4d commit 3ba0865

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

setup.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
with open(os.path.join(os.path.dirname(__file__), "sqlalchemy_cockroachdb", "__init__.py")) as v:
77
VERSION = re.compile(r'.*__version__ = "(.*?)"', re.S).match(v.read()).group(1)
88

9-
readme = os.path.join(os.path.dirname(__file__), "README.md")
9+
with open(os.path.join(os.path.dirname(__file__), "README.md")) as f:
10+
README = f.read()
1011

1112
setup(
1213
name="sqlalchemy-cockroachdb",
@@ -15,13 +16,17 @@
1516
author_email="cockroach-db@googlegroups.com",
1617
url="https://github.com/cockroachdb/sqlalchemy-cockroachdb",
1718
description="CockroachDB dialect for SQLAlchemy",
18-
long_description=open(readme).read(),
19+
long_description=README,
1920
long_description_content_type="text/markdown",
2021
license="http://www.apache.org/licenses/LICENSE-2.0",
2122
classifiers=[
2223
"License :: OSI Approved :: Apache Software License",
23-
"Programming Language :: Python :: 2",
2424
"Programming Language :: Python :: 3",
25+
"Programming Language :: Python :: 3 :: Only",
26+
"Programming Language :: Python :: 3.6",
27+
"Programming Language :: Python :: 3.7",
28+
"Programming Language :: Python :: 3.8",
29+
"Programming Language :: Python :: 3.9",
2530
],
2631
keywords="SQLAlchemy CockroachDB",
2732
project_urls={

sqlalchemy_cockroachdb/base.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def connect(
103103
**kwargs,
104104
):
105105
self.disable_cockroachdb_telemetry = disable_cockroachdb_telemetry
106-
return super(CockroachDBDialect, self).connect(
106+
return super().connect(
107107
dsn, connection_factory,
108108
cursor_factory, **kwargs)
109109

@@ -114,7 +114,7 @@ def __init__(self, *args, **kwargs):
114114
raise NotImplementedError("server_side_cursors is not supported")
115115
kwargs["use_native_hstore"] = False
116116
kwargs["server_side_cursors"] = False
117-
super(CockroachDBDialect, self).__init__(*args, **kwargs)
117+
super().__init__(*args, **kwargs)
118118

119119
@classmethod
120120
def dbapi(cls):
@@ -151,7 +151,7 @@ def initialize(self, connection):
151151
version = pkg_resources.require("sqlalchemy-cockroachdb")[0].version
152152
telemetry_query = (
153153
"SELECT crdb_internal.increment_feature_counter"
154-
+ "('SQLAlchemy {version}')".format(version=version)
154+
+ f"('SQLAlchemy {version}')"
155155
)
156156
connection.execute(text(telemetry_query))
157157

@@ -190,7 +190,7 @@ def get_columns(self, conn, table_name, schema=None, **kw):
190190
# Oh well. Hoping 1.1 won't be around for long.
191191
rows = conn.execute(
192192
text(
193-
'SHOW COLUMNS FROM "%s"."%s"' % (schema or self.default_schema_name, table_name)
193+
f'SHOW COLUMNS FROM "{schema or self.default_schema_name}"."{table_name}"'
194194
)
195195
)
196196
elif not self._is_v191plus:
@@ -234,7 +234,7 @@ def get_columns(self, conn, table_name, schema=None, **kw):
234234
try:
235235
type_class = _type_map[type_name.lower()]
236236
except KeyError:
237-
warn("Did not recognize type '%s' of column '%s'" % (type_name, name))
237+
warn(f"Did not recognize type '{type_name}' of column '{name}'")
238238
type_class = sqltypes.NULLTYPE
239239
if type_args:
240240
typ = type_class(*[int(s.strip()) for s in type_args.split(",")])
@@ -350,7 +350,7 @@ def get_foreign_keys_v1(self, conn, table_name, schema=None, **kw):
350350

351351
for row in conn.execute(
352352
text(
353-
'SHOW CONSTRAINTS FROM "%s"."%s"' % (schema or self.default_schema_name, table_name)
353+
f'SHOW CONSTRAINTS FROM "{schema or self.default_schema_name}"."{table_name}"'
354354
)
355355
):
356356
if row.Type.startswith("FOREIGN KEY"):
@@ -483,7 +483,7 @@ def get_foreign_keys(
483483

484484
def get_pk_constraint(self, conn, table_name, schema=None, **kw):
485485
if self._is_v21plus:
486-
return super(CockroachDBDialect, self).get_pk_constraint(conn, table_name, schema, **kw)
486+
return super().get_pk_constraint(conn, table_name, schema, **kw)
487487

488488
# v2.0 does not know about enough SQL to understand the query done by
489489
# the upstream dialect. So run a dumbed down version instead.
@@ -505,7 +505,7 @@ def get_pk_constraint(self, conn, table_name, schema=None, **kw):
505505

506506
def get_unique_constraints(self, conn, table_name, schema=None, **kw):
507507
if self._is_v21plus:
508-
return super(CockroachDBDialect, self).get_unique_constraints(
508+
return super().get_unique_constraints(
509509
conn, table_name, schema, **kw
510510
)
511511

@@ -525,7 +525,7 @@ def get_unique_constraints(self, conn, table_name, schema=None, **kw):
525525

526526
def get_check_constraints(self, conn, table_name, schema=None, **kw):
527527
if self._is_v21plus:
528-
return super(CockroachDBDialect, self).get_check_constraints(
528+
return super().get_check_constraints(
529529
conn, table_name, schema, **kw
530530
)
531531
# TODO(bdarnell): The postgres dialect implementation depends on
@@ -538,21 +538,21 @@ def do_savepoint(self, connection, name):
538538
if savepoint_state.cockroach_restart:
539539
connection.execute(text("SAVEPOINT cockroach_restart"))
540540
else:
541-
super(CockroachDBDialect, self).do_savepoint(connection, name)
541+
super().do_savepoint(connection, name)
542542

543543
def do_rollback_to_savepoint(self, connection, name):
544544
# Savepoint logic customized to work with run_transaction().
545545
if savepoint_state.cockroach_restart:
546546
connection.execute(text("ROLLBACK TO SAVEPOINT cockroach_restart"))
547547
else:
548-
super(CockroachDBDialect, self).do_rollback_to_savepoint(connection, name)
548+
super().do_rollback_to_savepoint(connection, name)
549549

550550
def do_release_savepoint(self, connection, name):
551551
# Savepoint logic customized to work with run_transaction().
552552
if savepoint_state.cockroach_restart:
553553
connection.execute(text("RELEASE SAVEPOINT cockroach_restart"))
554554
else:
555-
super(CockroachDBDialect, self).do_release_savepoint(connection, name)
555+
super().do_release_savepoint(connection, name)
556556

557557

558558
# If alembic is installed, register an alias in its dialect mapping.

sqlalchemy_cockroachdb/stmt_compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
| WITH
9191
| WORK
9292
"""
93-
CRDB_RESERVED_WORDS = set([x.strip().lower() for x in crdb_grammar_reserved.split("|")])
93+
CRDB_RESERVED_WORDS = {x.strip().lower() for x in crdb_grammar_reserved.split("|")}
9494

9595

9696
class CockroachIdentifierPreparer(PGIdentifierPreparer):

sqlalchemy_cockroachdb/transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def run_transaction(transactor, callback, max_retries=None, max_backoff=0):
4444
raise TypeError("don't know how to run a transaction on %s", type(transactor))
4545

4646

47-
class _NestedTransaction(object):
47+
class _NestedTransaction:
4848
"""Wraps begin_nested() to set the savepoint_state thread-local.
4949
5050
This causes the savepoint statements that are a part of this retry

0 commit comments

Comments
 (0)