fontParts icon indicating copy to clipboard operation
fontParts copied to clipboard

`point.py` annotations

Open roberto-arista opened this issue 1 year ago • 10 comments

Hey @benkiel,

As agreed in PR #739, I will create a separate PR for each module. I'm trying to follow the same patterns that @knutnergaard used in his PR. If I understand the work done so far correctly, I only need to annotate the module in fontParts.base, right?

@knutnergaard, could you review my proposal to ensure it follows the same steps as yours?

Since the work so far has focused on font.py and glyph.py, I plan to start with the smaller objects and work my way up.

cc: @typemytype

roberto-arista avatar Sep 24 '24 15:09 roberto-arista

Since the work so far has focused on font.py and glyph.py, I plan to start with the smaller objects and work my way up.

I've also annotated and revised layer.py and annotated base.py. BTW, it's a good idea to run mypy on the files before committing changes.

knutnergaard avatar Sep 25 '24 06:09 knutnergaard

Screenshot 2024-09-27 at 09 58 04

@knutnergaard I receive this error from Mypy. I see an identical method all across fontParts, so I assume the code is correct. Do you see it as well?

roberto-arista avatar Sep 27 '24 08:09 roberto-arista

@roberto-arista, Yes I get this as well. Likely it's caused by the fact that _contour is supposed to hold a weak reference to a BaseContour object, and should be annotated as such using weakref.ReferenceType. The base.reference function, however, returns the object instance itself, rather than a weak reference of it, so I'm not sure how this is supposed to work.

Can you clarify, @typesupply or @benkiel?

knutnergaard avatar Sep 27 '24 10:09 knutnergaard

Hey @knutnergaard we used to do weakref, that's why the comment is there, but we don't anymore for reasons here: https://github.com/robotools/fontParts/issues/71#issuecomment-362708807

benkiel avatar Sep 28 '24 01:09 benkiel

@benkiel I see. What's the purpose then of the base.reference function and how would you prefer we annotate this? If there is no chance of implementing the weakref in the future, I would suggest jut removing the method call in _getContour and other similar places. Otherwise, I guess the notation will have to be Optional[Union[BaseContour, ReferenceType[BaseContour]]], in which case a type alias is probably in order.

knutnergaard avatar Sep 28 '24 06:09 knutnergaard

@knutnergaard that's a @typesupply or @typemytype question. I'm hesitant to change that up as it has been working for years, but it may actually not matter and should have been cleaned up as you suggest when we dropped weakref. Wait until either chime in.

benkiel avatar Sep 28 '24 16:09 benkiel

What's the purpose then of the base.reference function and how would you prefer we annotate this?

Hmmmm. This is a really good question. I'm hesitant to change it because it may blow things up, but I'm 70% sure it won't. For now, let's do the following:

  1. Open an issue for me to review the necessity of the reference function. Add a link to #71.
  2. Delete the commented weakref code and add some documentation. Something like this:

This code returns a simple function that returns the given object. This is a backwards compatibility function that is under review. See (new issue number). We used to use weak references, but they proved problematic (see issue #71), so this function was put in place to make sure existing code continued to function. The need for it is questionable, so it may be deleted soon.

Does that work for everyone? I'd review it now but I don't trust my brain power to make such a big decision at the moment.

typesupply avatar Oct 03 '24 13:10 typesupply

@typesupply yes, that sounds good

benkiel avatar Oct 03 '24 21:10 benkiel

And, @typesupply that bit is done

benkiel avatar Oct 03 '24 22:10 benkiel

Thank you!

typesupply avatar Oct 03 '24 22:10 typesupply

@roberto-arista @knutnergaard a lot of things got added in the #739 PR. Maybe we need to add mypy checking?

benkiel avatar Nov 11 '24 18:11 benkiel

Here's an example of how I implemented it for the type annotations drawBot PR I worked on: https://github.com/roberto-arista/drawbot/blob/53924359d74418147392d2b04805b328139fc099/.github/workflows/test.yml#L43-L48

roberto-arista avatar Nov 11 '24 18:11 roberto-arista

@roberto-arista AH! that's nice

benkiel avatar Nov 11 '24 18:11 benkiel

@benkiel, I incorporated this into #739, so I think this can be closed. Can you confirm, @roberto-arista?

knutnergaard avatar Nov 11 '24 20:11 knutnergaard

fine with me!

roberto-arista avatar Nov 12 '24 09:11 roberto-arista

@knutnergaard or @roberto-arista do you want to add the mypy tests into the codebase? I'm not sure what I should (if anything) be ignoring, etc.

benkiel avatar Nov 12 '24 16:11 benkiel

I can give it a shot!

roberto-arista avatar Nov 12 '24 17:11 roberto-arista

@roberto-arista THANK YOU!

benkiel avatar Nov 12 '24 17:11 benkiel

I have some questions about implementing the type checking, I'll open a separate issue to discuss them.

roberto-arista avatar Nov 18 '24 08:11 roberto-arista