FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-144001: Support ignorechars in binascii.a2b_base64() and base64.b64decode() by serhiy-storchaka · Pull Request #144024 · python/cpython · GitHub

Repository navigation

gh-144001: Support ignorechars in binascii.a2b_base64() and base64.b64decode() - #144024

Merged
serhiy-storchaka merged 5 commits into
python:mainfrom
serhiy-storchaka:base64-decode-ignorechars
Jan 26, 2026
Merged

serhiy-storchaka merged 5 commits into
python:mainfrom
serhiy-storchaka:base64-decode-ignorechars

Conversation

serhiy-storchaka commented Jan 19, 2026 •
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member Author

This is a draft because I am going to apply the error handling changes in a separate issue first.

We can also apply some optimizations -- cache the ignored chars and returning on fast path after ignored characters.

serhiy-storchaka force-pushed the base64-decode-ignorechars branch from 1b0bb87 to 192d535 Compare January 19, 2026 11:19
serhiy-storchaka marked this pull request as ready for review January 19, 2026 11:20

Copy link
Copy Markdown
Member Author

Well, the issue with error handling was just that the error message could be more specific in some cases. It is not a bug. It can be included in this PR.

serhiy-storchaka force-pushed the base64-decode-ignorechars branch from 192d535 to 4f3847e Compare January 19, 2026 11:23
Comment thread Modules/binascii.c Outdated

Copy link
Copy Markdown
Contributor

No worries, that was the point I was just free on Sunday, so I push out a PR in case you haven't started on it. BTW your PR looks good, I am no maintainer but you just have to run ./python Tools/build/generate_global_objects.py to generate the updated header files. I hope it helps.

Comment thread Lib/base64.py
Comment thread Lib/test/test_base64.py Outdated

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM.

I'm fine with changing validate default to True if ignorechars is specified. The change produces more precise error messages. It also adds a lot of tests which is always a good thing :-)

serhiy-storchaka merged commit 7febbe6 into python:main Jan 26, 2026
51 checks passed
serhiy-storchaka deleted the base64-decode-ignorechars branch January 26, 2026 18:11

This comment was marked as off-topic.

This comment was marked as off-topic.

gpshead commented Jan 26, 2026

Copy link
Copy Markdown
Member

Taking a quick look: The docs in this PR changed the default for validate and strict_mode from False to True. But versionchanged does not mention that change and there was no deprecation period. Did this behavior change? The docs need fixing at a minimum but if the behavior changed we also need a deprecation cycle. What I understand @vstinner above to be saying is to change the default only in the case of the new parameter being supplied?

gpshead commented Jan 26, 2026

Copy link
Copy Markdown
Member

that may just be a simple doc fix. the declaration lines need to not state a value for the parameters who's default behavior varies based on context:

.. function:: b64decode(s, altchars=None, validate=False)
              b64decode(s, altchars=None, validate=True, *, ignorechars)
.. function:: a2b_base64(string, /, *, strict_mode=False)
              a2b_base64(string, /, *, strict_mode=True, ignorechars)

The text below describes a dynamic behavior on both, but people will absolutely misread the function signature and not read the text if we do not indicate it in the signature.

Copy link
Copy Markdown
Member Author

Sorry, I do not understand. How is it different from what is in the documentation now?

Copy link
Copy Markdown
Member Author

Deprecation period is needed if we want to change the existing behavior into error. But ignorechars is new, there was no existing behavior which was changed.

Copy link
Copy Markdown
Member

Taking a quick look: The docs in this PR changed the default for validate and strict_mode from False to True. But versionchanged does not mention that change and there was no deprecation period. Did this behavior change?

The default remains validate=False (no change). The behavior only changes if you start using the new ignorechars parameter.

Copy link
Copy Markdown
Member
.. function:: b64decode(s, altchars=None, validate=False)
              b64decode(s, altchars=None, validate=True, *, ignorechars)

I like that. It's quick to read.

thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

7 participants


Back | FazBrowse Home | New Git URL