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

Determine usefulness of attr validators as validation is done by fontTools.ufoLib already #27

Open
madig opened this issue May 17, 2019 · 10 comments

Comments

@madig
Copy link
Collaborator

madig commented May 17, 2019

In [1]: u = ufoLib2.Font()

In [14]: u.info.openTypeOS2WeightClass = -200                                                    

In [15]: u.info.openTypeOS2WeightClass                                                           
Out[15]: -200
@anthrotype
Copy link
Member

Yeah, attrs validators only work in the constructor

@madig
Copy link
Collaborator Author

madig commented May 25, 2019

Hm... ufoLib will prevent me from saving the invalid data to disk. It will probably also prevent loading of such data. So.. maybe having validators that only fire on instantiation aren't that useful in ufoLib2?

@anthrotype
Copy link
Member

There is attrs.validate function
http://www.attrs.org/en/stable/api.html

@madig
Copy link
Collaborator Author

madig commented May 25, 2019

Which runs all validators, not desirable if you just set one property, no?

@anthrotype
Copy link
Member

You want to run that just before serialisation. Maybe Font.save method should call that automatically.

@anthrotype
Copy link
Member

I don’t want to wrap every attribute in a @property just to ensure validators are run. Consenting adults

@madig
Copy link
Collaborator Author

madig commented May 25, 2019

Well, ufoLib already validates on (de)serialization, so maybe we can do away with validators entirely? Setters would not be affected. Dunno, just a thought. Although there would be no checks for when you do everything in memory, but I suppose that isn't covered currently anyway.

@madig
Copy link
Collaborator Author

madig commented Aug 17, 2019

To do:

  1. Determine which attributes (should) have validators and cross-check with fontTools.ufoLib to see if they are checked there.
  2. Decide if or which of these attributes should be turned into properties so that validators are always run; alternative: drop (all?) validators and let fontTools.ufoLib validate on serialization.

@madig madig changed the title Info: @openTypeOS2WeightClass.validator doesn't fire Determine usefulness of attr validators as validation is done by fontTools.ufoLib already Aug 17, 2019
@anthrotype
Copy link
Member

i'd say, drop all unnecessary validators that checks data integrity, which are already done in ufoLib.
and let static typechecker deal with the rest

@anthrotype
Copy link
Member

running attrs.validate() on attrs objects before serialization is still a good idea, it may catch things before it's too late.

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