-
Notifications
You must be signed in to change notification settings - Fork 491
Break off typing part of #3826 #3952
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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 had a quick look and left some comments on the typing vs runtime separation
from typing import overload | ||
from typing_extensions import Self | ||
|
||
from fontTools.ttLib.tables import ( |
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.
How about from fontTools.ttLib import tables
?
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.
Then with ... -> "tables._c_m_a_p.table__c_m_a_p": ...
I get "_c_m_a_p" is not a known attribute of module "fontTools.ttLib.tables" Pylance
. Unless you know a trick, I have explicitly import all of them :(
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.
One could maybe change MetaTools/buildTableList.py to place an explicit __all__ = [ ... ]
into the generated tables module.
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.
Hmm yea annoying... I suppose an __all__
would be best, but that's probably out of scope
Would it help if I'd open a PR to this branch with my proposed changes? |
Feel free! @dscorbett @anthrotype Maybe I'm confused about Tag and str. What should I do here? Do we expect the Tag class, which extends str? Should we allow both? Or just str? |
8c189ae
to
3fc2594
Compare
3fc2594
to
18e2836
Compare
Co-authored-by: schriftgestalt <georg.seifert@mac.com>
18e2836
to
515fa76
Compare
@jorenham I'm confused about the fonttools/Lib/fontTools/ttLib/ttFont.py Line 1346 in 515fa76
renormalizeLocation the return type dict[str, float] , but the type checker didn't like it:
|
I have changed all typings of Tag to just fonttools/Lib/fontTools/ttLib/ttFont.py Line 854 in 515fa76
|
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'll try to work on this this weekend, so consider the comments "notes to self".
But I really like what you've done so far.
from typing import overload | ||
from typing_extensions import Self | ||
|
||
from fontTools.ttLib.tables import ( |
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.
Hmm yea annoying... I suppose an __all__
would be best, but that's probably out of scope
cce862b
to
83142cb
Compare
@jorenham The number type issue remains, otherwise I tried to simplify a bit. |
I wasn't able to find the time to work on this, sorry about that.
I'll take a look at it soon |
See #3826 for context.
This tries to port only the type hints (plus some import sorting and asserts to please the type checkers) and nothing else.
I think it would be nice to overload
__getitem__
andget
so that e.g.font["cmap"]
is correctly typed asttLib.tables._c_m_a_p.table__c_m_a_p
👀@jorenham In case you're still interested :)
Closes #3954.