jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1326315?usp=email )

Change subject: api: Keep encoded parameter values distinct
......................................................................

api: Keep encoded parameter values distinct

Use separate names for singleton, formatted, and encoded request values.
This makes each transformation explicit without changing serialization.

Change-Id: I026c39e6204fa8e0af1f874cb1f7b784f995791a
---
M pywikibot/data/api/_requests.py
1 file changed, 11 insertions(+), 9 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py
index e0b263e..e1ed5cf 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -475,36 +475,38 @@
         :return: Parameters either in the site encoding, or ASCII
             strings
         """
-        params = {}
+        params: dict[str, str | bytes] = {}
         for key, values in self._params.items():
             try:
                 iterator = values.api_iter()
             except AttributeError:
                 if len(values) == 1:
-                    value = values[0]
-                    if value is True:
+                    single_value = values[0]
+                    if single_value is True:
                         values = ['']
-                    elif value is False or value is None:
+                    elif single_value is False or single_value is None:
                         # False and None are not included in the http URI
                         continue
                 iterator = iter(values)
-            value = '|'.join(self._format_value(value) for value in iterator)
+            formatted_value = '|'.join(
+                self._format_value(item) for item in iterator)
+            param_value: str | bytes = formatted_value
             # If the value is encodable as ascii, do not encode it.
             # This means that any value which can be encoded as ascii
             # is presumed to be ascii, and servers using a site encoding
             # which is not a superset of ascii may be problematic.
             try:
-                value.encode('ascii')
+                formatted_value.encode('ascii')
             except UnicodeError:
                 try:
-                    value = value.encode(self.site.encoding())
+                    param_value = formatted_value.encode(self.site.encoding())
                 except Exception:
                     pywikibot.error(
                         f'_encoded_items: {key!r} could not be encoded as '
-                        f'{self.site.encoding()!r}: {value!r}')
+                        f'{self.site.encoding()!r}: {formatted_value!r}')
             assert key.encode('ascii')
             assert isinstance(key, str)
-            params[key] = value
+            params[key] = param_value
         return params

     def _http_param_string(self):

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1326315?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I026c39e6204fa8e0af1f874cb1f7b784f995791a
Gerrit-Change-Number: 1326315
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to