classification
Title: html.escape can be used in a few places in the standard lib instead of similar existing code
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: andrei.avk, ezio.melotti
Priority: normal Keywords:

Created on 2021-06-20 03:40 by andrei.avk, last changed 2021-06-26 13:22 by terry.reedy.

Messages (1)
msg396161 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-06-20 03:40
There are a few places where old code does essentially the same thing as `html.escape()`, and can be replaced with html.escape():

 - more readable
 - less error prone on refactorings
 - will benefit if html.escape() performance is improved in the future
 - will be easier to grep for in case in the future html.escape() is enhanced with new escapes & it will be useful to consider applying it to all instances where it is used.

Here's what I found:

https://github.com/python/cpython/blob/main/Lib/difflib.py#L1914

https://github.com/python/cpython/blob/09eb81711597725f853e4f3b659ce185488b0d8c/Lib/plistlib.py#L158

https://github.com/python/cpython/blob/09eb81711597725f853e4f3b659ce185488b0d8c/Lib/pydoc.py#L525

https://github.com/python/cpython/blob/09eb81711597725f853e4f3b659ce185488b0d8c/Lib/xml/dom/minidom.py#L306

(^ keep existing escape of double quote)

https://github.com/python/cpython/blob/09eb81711597725f853e4f3b659ce185488b0d8c/Lib/xml/sax/saxutils.py#L27

https://github.com/python/cpython/blob/09eb81711597725f853e4f3b659ce185488b0d8c/Lib/xmlrpc/client.py#L149

I can add a PR if this sounds good.
History
Date User Action Args
2021-06-26 13:22:26terry.reedysetnosy: + ezio.melotti
2021-06-20 03:40:30andrei.avkcreate