Skip to content
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

Use decorator style properties #222

Open
lianghai opened this issue Jun 17, 2022 · 1 comment
Open

Use decorator style properties #222

lianghai opened this issue Jun 17, 2022 · 1 comment

Comments

@lianghai
Copy link

Problem

Some recent changes (eg, #189) have created difficulties for Pylance/Pyright to infer that Font.kerning is of type Kerning:

Screen Shot 2022-06-17 at 15 45 41

See also a non-property for comparison:

Screen Shot 2022-06-17 at 15 45 24

Is it because that the property class isn’t generic? I tried to look into issue tickets in the Pylance and Pyright projects but haven’t found anything helpful.

Potential solution

Seems it works alright if we write the properties (eg, .kerning and .lib) in the decorator style:

Screen Shot 2022-06-17 at 15 54 31

To be clear, I don’t really understand type checkers enough to tell if the decorator method is an arbitrary workaround or a long term solution, and I certainly don’t want to make the maintainers to randomly patch ufoLib2 only for some specific type checkers’ temporary limitations…

@madig
Copy link
Collaborator

madig commented Jun 21, 2022

I have not looked into this too deeply, but I think Pylance and others have trouble with attrs doing its own thing. Adding a Kerning annotation to the kerning property fixes the type but leads to mistyping error. Feel free to search https://github.com/microsoft/pylance-release/issues and https://github.com/microsoft/pylance-release/discussions for pointers.

I forgot why we do the kerning = property(_get_kerning, _set_kerning) line... maybe your fix is enough. Will look at this at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants