Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add typing to AFM parser#30134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
QuLogic wants to merge1 commit intomatplotlib:text-overhaul
base:text-overhaul
Choose a base branch
Loading
fromQuLogic:afm-typing

Conversation

QuLogic
Copy link
Member

PR summary

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

PR checklist

@@ -376,7 +394,8 @@ def get_str_bbox_and_descent(self, s):
except KeyError:
name = 'question'
wx, _, bbox = self._metrics_by_name[name]
total_width += wx + self._kern.get((namelast, name), 0)
total_width += wx
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm uncertain ifWX is the only thing that can be a float, or that's a parsing bug.

@QuLogic
Copy link
MemberAuthor

Also,pyright (though notmypy) notes that since the keys of theFontMetricsHeader 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?

@QuLogicQuLogic added this to thev3.11.0 milestoneJun 5, 2025
@QuLogicQuLogic moved this toReady for Review inFont and text overhaulJun 5, 2025
@QuLogicQuLogic changed the base branch frommain totext-overhaulJune 11, 2025 02:56
@QuLogic
Copy link
MemberAuthor

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

@tacaswell
Copy link
Member

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

Copy link
Member

@ksundenksunden left a 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

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*).
Copy link
Member

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

Copy link
MemberAuthor

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.

Copy link
Member

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.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Same as CharMetrics

Also, check some expected conditions at parse time instead of somewhereduring use of the data.
@jkseppan
Copy link
Member

jkseppan commentedJun 20, 2025
edited
Loading

Also,pyright (though notmypy) notes that since the keys of theFontMetricsHeader 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

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

for all of the accesses. The if statement letspyright narrow the type.

@jkseppan
Copy link
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 discussionon Gitter but since there clearly are different opinions, I don't think we should decide this too hastily.

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

@jkseppanjkseppanjkseppan left review comments

@ksundenksundenksunden left review comments

Assignees
No one assigned
Projects
Status: Ready for Review
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

4 participants
@QuLogic@tacaswell@jkseppan@ksunden

[8]ページ先頭

©2009-2025 Movatter.jp