Skip to content

Update #3078 - Force any non-NoneType to string - #3090

Merged
Anteru merged 2 commits into
pygments:masterfrom
styx0x6:master
May 3, 2026
Merged

Anteru merged 2 commits into
pygments:masterfrom
styx0x6:master

Conversation

@styx0x6

@styx0x6 styx0x6 commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor

Hi @Anteru , @birkenfeld ,

Following up #3078 (which fixes #3076), I would like to improve a quite bite the html_escape function for the 2.20.1 release.

@Anteru you said in #3078:

Eventually, we can even add strong types to it (str | None) in this case.

I found this issue recently that would justify strong types : lepture/shibuya#113

This time an int type is initiated. Some attributes from HtmlFormatter definitely shouldn't be inititiated with other types than string (right?), but I suggest, as you mentioned it above @Anteru , to force strong type str when it's not NoneType, then no more of this kind of issue may be raised.

@styx0x6

styx0x6 commented Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

Concerning that change. It's just to ensure that escaping will not generate more break, but we are agree that clients code must properly handle passed values. One doesn't preclude the other I think. I let you choose if it must be harden here or not.

@Anteru Anteru added this to the 2.21.0 milestone May 3, 2026
@Anteru Anteru self-assigned this May 3, 2026
@Anteru

Anteru commented May 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks, merged!

Note a huge fan of adding type annotations but given the trouble here, and increased use of AI bots, I think it's ok to gradually introduce type hints - any thoughts @birkenfeld ?

@Anteru
Anteru merged commit faa0209 into pygments:master May 3, 2026
17 checks passed
@birkenfeld

Copy link
Copy Markdown
Member

Yeah, it seems to be the trend nowadays, I've trained myself to not care about it anymore :)

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.

mkdocs build fails in HtmlFormatter with 'NoneType' object has no attribute 'replace'

3 participants