Copilot commented on code in PR #4653:
URL: https://github.com/apache/cassandra/pull/4653#discussion_r3051878750


##########
pylib/cqlshlib/saferscanner.py:
##########
@@ -30,6 +30,7 @@ class SaferScannerBase(re.Scanner):
 
     @classmethod
     def subpat(cls, phrase, flags):
+        # pylint: disable=no-member
         return cls.scrub_sub(re.sre_parse.parse(phrase, flags), flags)

Review Comment:
   The standalone `# pylint: disable=no-member` directives inside methods 
disable the check for the remainder of the current scope (function/method), 
which can unintentionally hide real `no-member` issues later in the same 
method. Prefer either (a) importing the internal modules explicitly (e.g., 
`from re import sre_parse` / `from re import _parser`) so Pylint can resolve 
the symbols without suppression, or (b) using a tightly-scoped disable/enable 
pair around only the minimal block that needs it.



##########
pylib/cqlshlib/saferscanner.py:
##########
@@ -38,6 +39,7 @@ def scrub_sub(cls, sub, flags):
         seqtypes = (type(()), type([]))
         for op, arg in sub.data:
             if type(arg) in seqtypes:
+                # pylint: disable=no-member
                 arg = [cls.scrub_sub(a, flags) if isinstance(a, 
re.sre_parse.SubPattern) else a

Review Comment:
   The standalone `# pylint: disable=no-member` directives inside methods 
disable the check for the remainder of the current scope (function/method), 
which can unintentionally hide real `no-member` issues later in the same 
method. Prefer either (a) importing the internal modules explicitly (e.g., 
`from re import sre_parse` / `from re import _parser`) so Pylint can resolve 
the symbols without suppression, or (b) using a tightly-scoped disable/enable 
pair around only the minimal block that needs it.



##########
pylib/cqlshlib/saferscanner.py:
##########
@@ -49,6 +51,7 @@ def scrub_sub(cls, sub, flags):
             raise ValueError("Named captures not allowed in SaferScanner 
lexicon")
         if sub.pattern.flags ^ flags:
             raise ValueError("RE flag setting not allowed in SaferScanner 
lexicon (%s)" % (bin(sub.pattern.flags),))
+        # pylint: disable=no-member
         return re.sre_parse.SubPattern(sub.pattern, scrubbedsub)

Review Comment:
   The standalone `# pylint: disable=no-member` directives inside methods 
disable the check for the remainder of the current scope (function/method), 
which can unintentionally hide real `no-member` issues later in the same 
method. Prefer either (a) importing the internal modules explicitly (e.g., 
`from re import sre_parse` / `from re import _parser`) so Pylint can resolve 
the symbols without suppression, or (b) using a tightly-scoped disable/enable 
pair around only the minimal block that needs it.



##########
pylib/cqlshlib/saferscanner.py:
##########
@@ -57,6 +60,7 @@ class Py36SaferScanner(SaferScannerBase):
     def __init__(self, lexicon, flags=0):
         self.lexicon = lexicon
         p = []
+        # pylint: disable=no-member
         s = re.sre_parse.Pattern()

Review Comment:
   The standalone `# pylint: disable=no-member` directives inside methods 
disable the check for the remainder of the current scope (function/method), 
which can unintentionally hide real `no-member` issues later in the same 
method. Prefer either (a) importing the internal modules explicitly (e.g., 
`from re import sre_parse` / `from re import _parser`) so Pylint can resolve 
the symbols without suppression, or (b) using a tightly-scoped disable/enable 
pair around only the minimal block that needs it.



##########
pylib/cqlshlib/saferscanner.py:
##########
@@ -73,6 +77,7 @@ class Py38SaferScanner(SaferScannerBase):
     def __init__(self, lexicon, flags=0):
         self.lexicon = lexicon
         p = []
+        # pylint: disable=no-member
         s = re.sre_parse.State()

Review Comment:
   The standalone `# pylint: disable=no-member` directives inside methods 
disable the check for the remainder of the current scope (function/method), 
which can unintentionally hide real `no-member` issues later in the same 
method. Prefer either (a) importing the internal modules explicitly (e.g., 
`from re import sre_parse` / `from re import _parser`) so Pylint can resolve 
the symbols without suppression, or (b) using a tightly-scoped disable/enable 
pair around only the minimal block that needs it.



##########
pylib/cqlshlib/cqlhandling.py:
##########
@@ -132,6 +132,43 @@ def cql_parse(self, text, startsymbol='Start'):
         tokens = self.cql_massage_tokens(tokens)
         return self.parse(startsymbol, tokens, init_bindings={'*SRC*': text})
 
+    @staticmethod
+    def dequote_value(cqlword):
+        cqlword = cqlword.strip()
+        if cqlword == '':
+            return cqlword
+        if cqlword[0] == "'" and cqlword[-1] == "'":
+            cqlword = cqlword[1:-1].replace("''", "'")
+        return cqlword
+
+    @staticmethod
+    def dequote_name(name):
+        name = name.strip()
+        if name == '':
+            return name
+        if name[0] == '"' and name[-1] == '"':
+            return name[1:-1].replace('""', '"')
+        else:
+            return name.lower()
+
+    @staticmethod
+    def escape_value(value):
+        if value is None:
+            return 'NULL'  # this totally won't work
+        if isinstance(value, bool):
+            value = str(value).lower()
+        elif isinstance(value, float):
+            return '%f' % value
+        elif isinstance(value, int):
+            return str(value)

Review Comment:
   `escape_value()` assumes any non-bool/non-float/non-int value supports 
`.replace()`. If callers pass common non-string types (e.g., UUID, datetime), 
this will raise `AttributeError`. A concrete fix is to stringify the value 
before escaping (e.g., convert to `str` for the final branch, then apply 
`.replace()`), while keeping the existing special-casing for numeric/bool 
formatting.
   ```suggestion
               return str(value)
           value = str(value)
   ```



##########
pylib/cqlshlib/saferscanner.py:
##########
@@ -89,6 +94,7 @@ class Py311SaferScanner(SaferScannerBase):
     def __init__(self, lexicon, flags=0):
         self.lexicon = lexicon
         p = []
+        # pylint: disable=no-member
         s = re._parser.State()

Review Comment:
   The standalone `# pylint: disable=no-member` directives inside methods 
disable the check for the remainder of the current scope (function/method), 
which can unintentionally hide real `no-member` issues later in the same 
method. Prefer either (a) importing the internal modules explicitly (e.g., 
`from re import sre_parse` / `from re import _parser`) so Pylint can resolve 
the symbols without suppression, or (b) using a tightly-scoped disable/enable 
pair around only the minimal block that needs it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to