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

gh-139489: Add xml.is_valid_name() by serhiy-storchaka · Pull Request #139768 · python/cpython · GitHub

Repository navigation

gh-139489: Add xml.is_valid_name() - #139768

Merged
serhiy-storchaka merged 9 commits into
python:mainfrom
serhiy-storchaka:xml-sax-utils-is_valid_name
May 5, 2026
Merged

serhiy-storchaka merged 9 commits into
python:mainfrom
serhiy-storchaka:xml-sax-utils-is_valid_name

Conversation

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

Copy link
Copy Markdown
Member

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


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

It allows to check whether a string can be used as an element or attribute
name in XML.
Comment thread Doc/whatsnew/3.15.rst Outdated
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 commented Oct 8, 2025 •
edited
Loading

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?

Copy link
Copy Markdown
Member Author

There is no an xml.utils module.

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?

Copy link
Copy Markdown
Member Author

This is an interesting idea.

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown
Member

See also Place for XML helper functions discussion.

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

Copy link
Copy Markdown

serhiy-storchaka removed the stale Stale PR or inactive for long period of time. label May 1, 2026
Comment thread Doc/whatsnew/3.15.rst Outdated
Comment thread Lib/xml/utils.py Outdated
Co-authored-by: Victor Stinner <vstinner@python.org>
picnixz changed the title gh-139489: Add xml.sax.saxutils.is_valid_name() gh-139489: Add xml.utils.is_valid_name() May 2, 2026
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.

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

Maybe add a link to the specs if any?

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

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

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

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

Copy link
Copy Markdown
Member Author

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

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.

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

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

Comment thread Lib/xml/utils.py Outdated
@@ -0,0 +1,25 @@
lazy import re

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

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?

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

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).

Copy link
Copy Markdown
Member Author

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

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.

Comment thread Lib/xml/utils.py
@@ -0,0 +1,25 @@
lazy import re


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

I'd suggest adding an __all__

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

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'>

serhiy-storchaka changed the title gh-139489: Add xml.utils.is_valid_name() gh-139489: Add xml.is_valid_name() May 4, 2026

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 would prefer having a private sub-module (xml._utils), but I don't have a strong opinion on it.

serhiy-storchaka merged commit a76d957 into python:main May 5, 2026
58 checks passed
serhiy-storchaka deleted the xml-sax-utils-is_valid_name branch May 5, 2026 08:25
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.

5 participants


Back | FazBrowse Home | New Git URL