GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-139489: Add xml.is_valid_name() by serhiy-storchaka · Pull Request #139768 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Oct 8, 2025 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

It allows to check whether a string can be used as an element or attribute name in XML.

  • Issue: Add utility functions to test for legal XML characters and names #139489

📚 Documentation preview 📚: https://cpython-previews--139768.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
pythongh-139489: Add xml.sax.utils.is_valid_name()
c7cbb61
It allows to check whether a string can be used as an element or attribute
name in XML.
@serhiy-storchaka
serhiy-storchaka requested a review from AA-Turner as a code owner October 8, 2025 12:37
@bedevere-app bedevere-app Bot mentioned this pull request Oct 8, 2025
Add utility functions to test for legal XML characters and names #139489
Open
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 8, 2025
picnixz
picnixz reviewed Oct 8, 2025
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
Fix references.
4f37eed
@serhiy-storchaka serhiy-storchaka changed the title gh-139489: Add xml.sax.utils.is_valid_name() gh-139489: Add xml.sax.saxutils.is_valid_name() Oct 8, 2025
@vstinner

vstinner commented Oct 8, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Why not adding the function in the xml package level, for example in a xml.utils module?

The function doesn't seem to be specific to the sax implementation. Is it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Oct 8, 2025

Copy link
Copy Markdown
Member Author

There is no an xml.utils module.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Oct 8, 2025

Copy link
Copy Markdown
Member

There is no an xml.utils module.

I'm suggesting to create such xml.utils module. Ok maybe put the new function directly in the xml top-level package?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Oct 9, 2025

Copy link
Copy Markdown
Member Author

This is an interesting idea.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Apr 30, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 30, 2026
@vstinner

vstinner commented Apr 30, 2026

Copy link
Copy Markdown
Member

See also Place for XML helper functions discussion.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka added 3 commits April 30, 2026 20:17
@serhiy-storchaka
dd
6ac604e
@serhiy-storchaka
Move to the toplevel xml module.
e814cfa
@serhiy-storchaka
Use possesive quantifier for optimization.
bc26874
@read-the-docs-community

read-the-docs-community Bot commented Apr 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32523509 | 📁 Comparing 3245a65 against main (b413bc7)

  🔍 Preview build  

18 files changed · ± 18 modified

± Modified

  • faq/programming.html
  • howto/descriptor.html
  • howto/perf_profiling.html
  • library/compression.zstd.html
  • library/concurrency.html
  • library/email.policy.html
  • library/gc.html
  • library/http.cookies.html
  • library/statistics.html
  • library/tarfile.html
  • and 8 more...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
Merge branch 'main' into xml-sax-utils-is_valid_name
b631754
@serhiy-storchaka serhiy-storchaka removed the stale Stale PR or inactive for long period of time. label May 1, 2026
@serhiy-storchaka
Merge branch 'main' into xml-sax-utils-is_valid_name
8db41b9
vstinner
vstinner reviewed May 2, 2026
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/xml/utils.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka @vstinner
Apply suggestions from code review
7e96492
Co-authored-by: Victor Stinner <[email protected]>
@picnixz picnixz changed the title gh-139489: Add xml.sax.saxutils.is_valid_name() gh-139489: Add xml.utils.is_valid_name() May 2, 2026
picnixz
picnixz reviewed May 2, 2026
View reviewed changes
Comment thread Doc/library/xml.rst
``False`` otherwise.

Almost all characters are permitted in names, except control characters and
those which either are or reasonably could be used as delimiters.

@picnixz picnixz May 2, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Maybe add a link to the specs if any?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 2, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Link found in the implementation: https://www.w3.org/TR/xml/#NT-Name.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz May 2, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think it would be good to add it in the online docs as well. It'll be more accessible.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka May 2, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I am going to add several more functions. Some functions will need several links, and some links will be repeated for different functions. If we want to add links, it is better to add root links to the XML specifications at the top of the module documentation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz May 2, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That's also ok. As long as the online docs contain some links to some specifications, it's ok.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
picnixz
picnixz reviewed May 2, 2026
View reviewed changes
Comment thread Lib/xml/utils.py Outdated
@@ -0,0 +1,25 @@
lazy import re

@picnixz picnixz May 2, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Are we worried about the stability of xml.utils? Maybe we could have xml._utils first and then promote it to a public module later?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 2, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'm also in favor of making this sub-module private (rename to xml._utils). There is a risk that developers start depending on xml.utils.is_valid_name name and it would break projects if the function is moved later (ex: to xml/__init__.py).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka May 2, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

xml and xml.utils were two initial suggestions, and they got the same amount of voices. If there is a chance of xml.utils been documented officially, it is better to keep this name from beginning. It is also more pickle-friendly.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
picnixz
picnixz reviewed May 2, 2026
View reviewed changes
Comment thread Lib/xml/utils.py
@@ -0,0 +1,25 @@
lazy import re


@picnixz picnixz May 2, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'd suggest adding an __all__

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 2, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It's needed. Currently, the re module is exposed as a xml attribute:

$ ./python
>>> import xml
>>> xml.re
<module 're' from '/home/vstinner/python/main/Lib/re/__init__.py'>

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka serhiy-storchaka changed the title gh-139489: Add xml.utils.is_valid_name() gh-139489: Add xml.is_valid_name() May 4, 2026
@serhiy-storchaka
Import re as _re.
3245a65
vstinner
vstinner approved these changes May 4, 2026
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM.

I would prefer having a private sub-module (xml._utils), but I don't have a strong opinion on it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels May 4, 2026
@serhiy-storchaka
serhiy-storchaka merged commit a76d957 into python:main May 5, 2026
58 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label May 5, 2026
@serhiy-storchaka
serhiy-storchaka deleted the xml-sax-utils-is_valid_name branch May 5, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@picnixz picnixz picnixz left review comments
@vstinner vstinner vstinner approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@serhiy-storchaka @vstinner @picnixz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.