Skip to content

Type hints in _type1font.py#30187

Open
jkseppan wants to merge 1 commit into
matplotlib:mainfrom
jkseppan:typecheck-type1font
Open

Type hints in _type1font.py#30187
jkseppan wants to merge 1 commit into
matplotlib:mainfrom
jkseppan:typecheck-type1font

Conversation

@jkseppan

Copy link
Copy Markdown
Member

This file now passes mypy --strict (but its imports don't).

Improve error handling: a new class _ParseError instead of ValueError
or RuntimeError. Raise most of the errors from utility functions to
simplify the parsing logic. Move FontBBox parsing into a new utility
function.

@tacaswell tacaswell added this to the v3.11.0 milestone Jun 19, 2025
Comment thread lib/matplotlib/_type1font.py Outdated
Comment thread lib/matplotlib/_type1font.py Outdated
Comment thread lib/matplotlib/_type1font.py
Comment thread lib/matplotlib/_type1font.py Outdated
Comment thread lib/matplotlib/_type1font.py Outdated
Comment thread lib/matplotlib/_type1font.py Outdated

# Fill in the various *Name properties
if 'FontName' not in prop:
if not prop['FontName']:

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.

Can we be certain that an empty string is not allowed here (and below)?

Comment thread lib/matplotlib/_type1font.py Outdated
Comment thread lib/matplotlib/_type1font.py Outdated
Comment on lines -686 to -691
index_token = next(tokens)
if not index_token.is_number():
_log.warning(
f"Parsing encoding: expected number, got {index_token}"
)
continue

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.

This previously ignored parsing failures; did you intend to raise here?

Comment thread lib/matplotlib/_type1font.py Outdated
Comment thread lib/matplotlib/_type1font.py Outdated
This file now passes `mypy --strict` (but its imports don't).

Improve error handling: a new class _ParseError instead of ValueError
or RuntimeError. Raise most of the errors from utility functions to
simplify the parsing logic. Move FontBBox parsing into a new utility
function.
@QuLogic QuLogic force-pushed the typecheck-type1font branch from 57797eb to 6c045e5 Compare June 30, 2026 07:25
@QuLogic

QuLogic commented Jun 30, 2026

Copy link
Copy Markdown
Member

I rebased this and fixed the "easy" comments I made, i.e., the unused bits and the deprecated names. I also updated to the new type syntax. But there are still a couple unanswered questions above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants