Type checking for table classes? #2859
-
I'm using VSCode which does live type checking. In projects involving FontTools, it generates a lot of noise because it can't check the attributes of SFNT table classes. E.g. glyf = font["glyf"]
print(sorted(glyf.keys())
I've tried adding stubs for the TTFont object, but how can I define that specific keys return specific table classes? def __getitem__(self, tag: str) -> DefaultTable: ... BTW I've added the stubs I have so far to this new repo. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If it's just about suppressing the noise, perhaps use |
Beta Was this translation helpful? Give feedback.
TTFont
partially behaves like a dict, so I'd expect we should do something liketyping.TypedDict
, but I'm not sure how to do that for a class implementing the (Mutable)Mapping protocol.If it's just about suppressing the noise, perhaps use
typing.Any
instead ofDefaultTable
.