(cleanup) remove Python 2 remaining items#727
Conversation
There was a problem hiding this comment.
Pull request overview
This PR continues the Python 2 cleanup by removing remaining unicode/UnicodeMixin compatibility shims and updating tests/docs/code paths to assume Python 3-only semantics (the project now requires Python >=3.9).
Changes:
- Removes Python 2-era unicode patterns (
u'',__unicode__,UnicodeMixin) and normalizes string handling across driver and cqlengine. - Simplifies Python-version conditionals/fallback imports (e.g.,
WeakSetimports) and applies formatting-only refactors in several modules/tests. - Updates unit/integration tests and Sphinx config to reflect Python 3-only behavior and representations.
Reviewed changes
Copilot reviewed 34 out of 37 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_types.py | Replaces u'' literals with plain str in type read/write tests. |
| tests/unit/test_row_factories.py | Removes Python 3.0–3.6 conditional expectations for namedtuple creation. |
| tests/unit/test_orderedmap.py | Updates unicode-key tests to Python 3 str keys. |
| tests/unit/test_metadata.py | Replaces u'' literals with str in metadata CQL export tests. |
| tests/unit/test_marshalling.py | Updates UTF8/unicode expectations to Python 3 str and cleans up ordered map inserts. |
| tests/unit/advanced/test_insights.py | Removes Python-version-specific namespace logic and reformats expected dicts. |
| tests/integration/standard/test_query.py | Updates unicode query strings/column names to Python 3 str. |
| tests/integration/standard/test_cluster.py | Updates expected row tuples to Python 3 str. |
| tests/integration/cqlengine/model/test_udts.py | Updates unicode literals to Python 3 str. |
| tests/integration/cqlengine/model/test_model_io.py | Updates unicode literals to Python 3 str in model IO assertions. |
| tests/integration/cqlengine/model/test_class_construction.py | Mostly formatting + Python 3 iterator usage (next(iter(...))) and string literal normalization. |
| tests/integration/cqlengine/columns/test_validation.py | Removes old Python-version branches and normalizes string usage/formatting in validation tests. |
| setup.py | Removes Python 2-era subprocess gating and refactors extension/doc build setup logic. |
| docs/conf.py | Normalizes string literals and formatting in Sphinx configuration. |
| cassandra/query.py | Python 3 string/formatting cleanup; keeps namedtuple fallback paths but modernizes literals/layout. |
| cassandra/pool.py | Removes legacy WeakSet fallback and reformats/shard-aware related code blocks. |
| cassandra/io/asyncorereactor.py | Removes legacy WeakSet fallback and modernizes literals/formatting. |
| cassandra/encoder.py | Deprecates Python 2 “unicode” semantics and standardizes encoding/quoting behavior for Python 3. |
| cassandra/datastax/graph/query.py | Python 3 string/formatting cleanup and minor readability refactors. |
| cassandra/datastax/graph/graphson.py | Python 3 cleanup + formatting; updates docs/comments describing supported Python types. |
| cassandra/datastax/graph/fluent/_query.py | Python 3 string/formatting cleanup and improves readability of traversal query generation. |
| cassandra/cqlengine/statements.py | Removes UnicodeMixin usage and converts __unicode__ implementations to __str__. |
| cassandra/cqlengine/operators.py | Removes UnicodeMixin usage and converts operator stringification to __str__. |
| cassandra/cqlengine/named.py | Converts __unicode__ to __str__ and normalizes string literals. |
| cassandra/cqlengine/models.py | Removes UnicodeMixin usage and normalizes string literals/formatting across model machinery. |
| cassandra/cqlengine/functions.py | Removes UnicodeMixin usage and converts __unicode__ to __str__. |
| cassandra/cqlengine/init.py | Removes UnicodeMixin definition entirely. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Fixed all comments. |
|
@copilot code review[agent] - please re-review |
Review: Rebased onto master, Python 3 expert reviewRebase StatusRebased all 18 commits onto current Review FindingsThe 18 commits are semantically correct. The bulk of the diff is formatting (quote normalization, import reformatting). All major semantic changes verified:
Issues Found
Finding #1 is the most important — it's a latent runtime error that would crash if an unknown prepared statement is executed (error logging path). |
59b6813 to
8103cf8
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 35 out of 38 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
absolute_import is the default behavior in Python 3 and has been since Python 3.0. The import was only needed for Python 2 compatibility.
UnicodeMixin was a Python 2 compatibility shim that made __str__ delegate to __unicode__. In Python 3, __str__ is the native method and UnicodeMixin serves no purpose. Affected classes: QueryValue, BaseQueryOperator, AbstractQueryableColumn, ValueQuoter, BaseClause, BaseCQLStatement.
In Python 3, __str__ is the native string method. The __unicode__ methods were a Python 2 convention used together with UnicodeMixin. Affected files: statements.py, operators.py, named.py, models.py, query.py, functions.py.
__nonzero__ was the Python 2 name for the boolean conversion method. Python 3 uses __bool__ directly.
weakref.WeakSet has been available since Python 2.7 and is always present in Python 3. Remove the try/except fallback imports in cluster.py, pool.py, and asyncorereactor.py, and delete the custom _IterationGuard and WeakSet classes from util.py (~210 lines).
… 3.9+ - cluster.py: remove 'if sys.version_info >= 3.7' guard around eventlet check (always true since we require Python 3.9+). Update error message. - test_insights.py: remove 'if sys.version_info > (3,)' guard around namespace suffix (always true). - test_row_factories.py: remove NAMEDTUPLE_CREATION_BUG flag and Python 3.0-3.6 warning path (bug was fixed in Python 3.7).
subprocess has been part of the standard library since Python 2.4. Also fixes: - Use sys.executable instead of hardcoded 'python' for subprocess calls - Use 'python -m sphinx' instead of 'sphinx-build' for docs - Fix get_subdriname() bug: was iterating over characters of a string path instead of calling os.listdir() on the path - Remove duplicate is_macos definition
In Python 3, the u'' prefix on string literals is a no-op (str is always unicode). Remove 150 occurrences across 15 files. Also update cql_encode_unicode() in encoder.py to pass the string directly to cql_quote() instead of encoding to UTF-8 bytes first, since Python 3 strings are always unicode.
- test_validation.py: remove 'if sys.version_info < (3, 1)' blocks that tested unichr() (only available in Python 2). Also fix 'class DataType():' to 'class DataType:'. - test_metadata.py: delete test_export_keyspace_schema_udts which was skipped on all Python versions except 2.7.
The workaround pre-loaded the UTF-8 encoding module to avoid a deadlock when importing from multiple threads. This bug was fixed in Python 3.3.
4778136 to
42e3d08
Compare
Pre-review checklist
This is 100% OpenCode's work. So take it with a grain of salt, and I need to go over it. I can also cherry-pick each one separately. I've asked it to separate as much as possible to independent items.
./docs/source/.Fixes:annotations to PR description.