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 — Add typing to AFM parser by QuLogic · Pull Request #30134 · matplotlib/matplotlib

Conversation

@QuLogic

@QuLogic QuLogic commented Jun 3, 2025

Copy link
Copy Markdown
Member

PR summary

Also, check some expected conditions at parse time instead of somewhere during use of the data.

PR checklist

  • [n/a] "closes #0000" is in the body of the PR description to link the related issue
  • new and changed code is tested
  • [n/a] Plotting related features are demonstrated in an example
  • [n/a] New Features and API Changes are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

Sorry, something went wrong.

Uh oh!

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

All reactions
QuLogic
QuLogic commented Jun 3, 2025
View reviewed changes
Comment thread lib/matplotlib/_afm.py Outdated
name = 'question'
wx, _, bbox = self._metrics_by_name[name]
total_width += wx + self._kern.get((namelast, name), 0)
total_width += wx

@QuLogic QuLogic Jun 3, 2025

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'm uncertain if WX is the only thing that can be a float, or that's a parsing bug.

Sorry, something went wrong.

Uh oh!

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

All reactions
@QuLogic
QuLogic force-pushed the afm-typing branch from 5722e56 to 603de89 Compare June 3, 2025 22:11
@github-actions github-actions Bot added the backend: ps label Jun 3, 2025
@QuLogic

QuLogic commented Jun 3, 2025

Copy link
Copy Markdown
Member Author

Also, pyright (though not mypy) notes that since the keys of the FontMetricsHeader are not required, they may cause an exception later in the property getters. Do we want to validate that earlier in the constructor, or mark those are required because we only intend to load known-good files?

All reactions

Sorry, something went wrong.

Uh oh!

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

@QuLogic
QuLogic force-pushed the afm-typing branch from 603de89 to 263a5c5 Compare June 4, 2025 21:54
@QuLogic QuLogic mentioned this pull request Jun 4, 2025
TYP: Make glyph indices distinct from character codes #30143
Merged
1 of 3 tasks
@QuLogic QuLogic added this to the v3.11.0 milestone Jun 5, 2025
@QuLogic QuLogic added this to Font and text overhaul Jun 5, 2025
@QuLogic QuLogic moved this to Ready for Review in Font and text overhaul Jun 5, 2025
@QuLogic
QuLogic changed the base branch from main to text-overhaul June 11, 2025 02:56
@QuLogic

QuLogic commented Jun 11, 2025

Copy link
Copy Markdown
Member Author

cc @jkseppan as you were going to do similar for _type1hint.py.

All reactions

Sorry, something went wrong.

Uh oh!

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

@tacaswell

tacaswell commented Jun 19, 2025

Copy link
Copy Markdown
Member

We should add a note to the dev docs that we are doing in-line type hints for private modules.

All reactions

Sorry, something went wrong.

Uh oh!

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

ksunden
ksunden reviewed Jun 19, 2025
View reviewed changes

@ksunden ksunden 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.

Overall looks good, aside from docstrings on the remade NamedTuples

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread lib/matplotlib/_afm.py Outdated
Comment on lines +189 to +194
width: float
#: The character width (WX).
name: str
#: The character name (N).
bbox: tuple[int, int, int, int]
#: The bbox of the character (B) as a tuple (*llx*, *lly*, *urx*, *ury*).

@ksunden ksunden Jun 19, 2025

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.

This does not include these comments as docstrings, which I think we would still prefer

I think we should be able to do the __doc__ manual lines still for the attributes

Sorry, something went wrong.

Uh oh!

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

All reactions

@QuLogic QuLogic Jun 19, 2025

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.

OK, moved back to those.

Sorry, something went wrong.

Uh oh!

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

All reactions

@jkseppan jkseppan Jun 20, 2025

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.

At least Sphinx picks up docstrings from the class body, but they have to be strings and not comments. While PEP 589 mentions that definitions can be "optionally preceded by a docstring" it seems that Sphinx uses the string following the definition.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread lib/matplotlib/_afm.py Outdated
Comment on lines +286 to +291
name: bytes
#: Name of the part, e.g. 'acute'.
dx: float
#: x-displacement of the part from the origin.
dy: float
#: y-displacement of the part from the origin.

@ksunden ksunden Jun 19, 2025

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.

Same as CharMetrics

Sorry, something went wrong.

Uh oh!

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

All reactions
@QuLogic
QuLogic force-pushed the afm-typing branch 2 times, most recently from 2896ae3 to f506d95 Compare June 19, 2025 22:17
jkseppan
jkseppan reviewed Jun 20, 2025
View reviewed changes
Comment thread lib/matplotlib/_afm.py Resolved

Uh oh!

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

jkseppan
jkseppan reviewed Jun 20, 2025
View reviewed changes
Comment thread lib/matplotlib/_afm.py Resolved

Uh oh!

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

@jkseppan

jkseppan commented Jun 20, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Also, pyright (though not mypy) notes that since the keys of the FontMetricsHeader are not required, they may cause an exception later in the property getters. Do we want to validate that earlier in the constructor, or mark those are required because we only intend to load known-good files?

Another option is to do something like

    def get_fontname(self) -> str:
        """Return the font name, e.g., 'Times-Roman'."""
        if 'FontName' not in self._header:
            raise LookupError(
                'Font name not found in AFM header. '
                'This may be due to an incomplete or malformed AFM file.'
            )
        return self._header['FontName']

for all of the accesses. The if statement lets pyright narrow the type.

All reactions

Sorry, something went wrong.

Uh oh!

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

@jkseppan

jkseppan commented Jun 20, 2025

Copy link
Copy Markdown
Member

We should add a note to the dev docs that we are doing in-line type hints for private modules.

Should we discuss the overall direction regarding type hints? There was some discussion on Gitter but since there clearly are different opinions, I don't think we should decide this too hastily.

All reactions

Sorry, something went wrong.

Uh oh!

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

@QuLogic
Add typing to AFM parser
a018606
Also, check some expected conditions at parse time instead of somewhere
during use of the data.
@QuLogic
QuLogic force-pushed the afm-typing branch from f506d95 to a018606 Compare July 8, 2025 05:33
tacaswell
tacaswell approved these changes Jul 8, 2025
View reviewed changes
jkseppan
jkseppan approved these changes Jul 9, 2025
View reviewed changes
@QuLogic
QuLogic merged commit f231f2e into matplotlib:text-overhaul Jul 9, 2025
@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Font and text overhaul Jul 9, 2025
@QuLogic
QuLogic deleted the afm-typing branch July 9, 2025 05:46
wavebyrd pushed a commit to wavebyrd/matplotlib that referenced this pull request Mar 13, 2026
@QuLogic
Merge pull request matplotlib#30134 from QuLogic/afm-typing
38a44c0
Add typing to AFM parser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ksunden ksunden ksunden left review comments
@jkseppan jkseppan jkseppan approved these changes
@tacaswell tacaswell tacaswell approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

backend: ps

Projects

Font and text overhaul
Status: Done

Milestone

v3.11.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

4 participants

@QuLogic @tacaswell @jkseppan @ksunden
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.