Skip to content

Use raw strings in some docstrings to avoid SyntaxWarning in Python 3.12 . #1205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

rtb-zla-karma
Copy link
Contributor

Prevent error logs on program startup:

/python/path/lib/python3.12/site-packages/cassandra/cqlengine/connection.py:318: SyntaxWarning: invalid escape sequence '\*'

These will turn into SyntaxErrors in future python versions. Source: https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences

Changed in version 3.12: Unrecognized escape sequences produce a SyntaxWarning. In a future Python version they will be eventually a SyntaxError.

@rtb-zla-karma rtb-zla-karma changed the title Use raw strings in some docstrings to avoid SyntaxWarning in Python 3… Use raw strings in some docstrings to avoid SyntaxWarning in Python 3.12 . Apr 30, 2024
@rtb-zla-karma rtb-zla-karma marked this pull request as ready for review April 30, 2024 14:21
@absurdfarce
Copy link
Collaborator

Greetings @rtb-zla-karma and thanks for the contribution!

Have you signed the Contributor License Agreement for contributions to DataStax open source projects? If not you can find it at https://cla.datastax.com/. Thanks!

@rtb-zla-karma
Copy link
Contributor Author

@absurdfarce I've signed it. Can we proceed?

@absurdfarce
Copy link
Collaborator

Thanks for signing @rtb-zla-karma! We can absolutely proceed now.

Good catch on this issue, although I do wonder if we might solve it just a bit differently. Rather than introducing an escaped syntax for only a few here blocks I'm wondering if we aren't better off just removing the escapes all together. I'm not sure they buy us enough to make it worthwhile.

What do you think about this instead?

$ git diff cassandra/cqlengine/*
diff --git a/cassandra/cqlengine/connection.py b/cassandra/cqlengine/connection.py
index 588e512a..20ef497a 100644
--- a/cassandra/cqlengine/connection.py
+++ b/cassandra/cqlengine/connection.py
@@ -323,7 +323,7 @@ def setup(
     :param int consistency: The global default :class:`~.ConsistencyLevel` - default is the same as :attr:`.Session.default_consistency_level`
     :param bool lazy_connect: True if should not connect until first use
     :param bool retry_connect: True if we should retry to connect even if there was a connection failure initially
-    :param \*\*kwargs: Pass-through keyword arguments for :class:`cassandra.cluster.Cluster`
+    :param kwargs: Pass-through keyword arguments for :class:`cassandra.cluster.Cluster`
     """
 
     from cassandra.cqlengine import models
diff --git a/cassandra/cqlengine/query.py b/cassandra/cqlengine/query.py
index 73f48a59..afc7ceee 100644
--- a/cassandra/cqlengine/query.py
+++ b/cassandra/cqlengine/query.py
@@ -205,8 +205,8 @@ class BatchQuery(object):
 
         :param fn: Callable object
         :type fn: callable
-        :param \*args: Positional arguments to be passed to the callback at the time of execution
-        :param \*\*kwargs: Named arguments to be passed to the callback at the time of execution
+        :param args: Positional arguments to be passed to the callback at the time of execution
+        :param kwargs: Named arguments to be passed to the callback at the time of execution
         """
         if not callable(fn):
             raise ValueError("Value for argument 'fn' is {0} and is not a callable object.".format(type(fn)))
@@ -276,8 +276,8 @@ class ContextQuery(object):
     A Context manager to allow a Model to switch context easily. Presently, the context only
     specifies a keyspace for model IO.
 
-    :param \*args: One or more models. A model should be a class type, not an instance.
-    :param \*\*kwargs: (optional) Context parameters: can be *keyspace* or *connection*
+    :param args: One or more models. A model should be a class type, not an instance.
+    :param kwargs: (optional) Context parameters: can be *keyspace* or *connection*
 
     For example:
 

@absurdfarce absurdfarce self-requested a review June 27, 2024 22:09
Copy link
Collaborator

@absurdfarce absurdfarce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for the quick turnaround @rtb-zla-karma!

@absurdfarce absurdfarce merged commit 7cdbdbb into datastax:master Jun 28, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants