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

Fix some annotation errors #762

Merged
merged 13 commits into from
Nov 2, 2024
10 changes: 4 additions & 6 deletions Lib/fontParts/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,19 +1357,17 @@ def _getIdentifier(self) -> str:
def _setIdentifier(self, value: str) -> None:
"""Force a specific identifier onto an object.

This method is intended for subclasses that allow setting an
identifier to a specific value.
This method is used internally to force a specific identifier onto an
object in certain situations.

:param value: The identifier to set as a :class:`str` or :obj:`None`.
:raises NotImplementedError: If the method has not been overridden by a
subclass.

.. note::

Subclasses may override this method.
Subclasses that allow setting an identifer may override this method.

"""
self.raiseNotImplementedError()
pass


def reference(obj: Callable[[], Any]) -> Callable[[], Any]:
Expand Down
21 changes: 15 additions & 6 deletions Lib/fontParts/base/glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
from fontParts.base.anchor import BaseAnchor
from fontParts.base.image import BaseImage

TempContourListType = List[
Tuple[int, int, IntFloatType, IntFloatType, IntFloatType, BaseContour]
]
ContourListType = List[
Tuple[int, int, FuzzyNumber, FuzzyNumber, IntFloatType, BaseContour]
]


class BaseGlyph(
BaseObject,
Expand Down Expand Up @@ -1772,6 +1779,8 @@ def appendAnchor(
normalizedPosition = normalizers.normalizeCoordinateTuple(position)
if color is not None:
normalizedColor = normalizers.normalizeColor(color)
else:
normalizedColor = None
normalizedIdentifier = normalizers.normalizeIdentifier(identifier)
return self._appendAnchor(
normalizedName,
Expand Down Expand Up @@ -2016,8 +2025,12 @@ def appendGuideline(
normalizedAngle = normalizers.normalizeRotationAngle(angle)
if name is not None:
normalizedName = normalizers.normalizeGuidelineName(name)
else:
normalizedName = None
if color is not None:
normalizedColor = normalizers.normalizeColor(color)
else:
normalizedColor = None
normalizedIdentifier = normalizers.normalizeIdentifier(identifier)
newGuideline = self._appendGuideline(
normalizedPosition,
Expand Down Expand Up @@ -2241,12 +2254,6 @@ def _autoContourOrder(self, **kwargs: Any) -> None:
:param \**kwargs: Additional keyword arguments.

"""
TempContourListType = List[
Tuple[int, int, IntFloatType, IntFloatType, IntFloatType, BaseContour]
]
ContourListType = List[
Tuple[int, int, FuzzyNumber, FuzzyNumber, IntFloatType, BaseContour]
]
tempContourList: TempContourListType = []
contourList: ContourListType = []
xThreshold: Optional[IntFloatType] = None
Expand Down Expand Up @@ -3282,6 +3289,8 @@ def addImage(
normalizedPosition = normalizers.normalizeTransformationOffset(position)
if color is not None:
normalizedColor = normalizers.normalizeColor(color)
else:
normalizedColor = None
sx, sy = normalizedScale
ox, oy = normalizedPosition
transformation = (sx, 0, 0, sy, ox, oy)
Expand Down
18 changes: 10 additions & 8 deletions Lib/fontParts/base/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from fontParts.base.annotations import (
CharacterMappingType,
CollectionType,
ColorType,
FactorType,
QuadrupleCollectionType,
TransformationType,
ReverseComponentMappingType,
)

Expand Down Expand Up @@ -780,19 +780,19 @@ def _set_name(self, value: str, **kwargs: Any) -> None:
""",
)

def _get_base_color(self) -> ColorType:
def _get_base_color(self) -> QuadrupleCollectionType[IntFloatType]:
value = self._get_color()
if value is not None:
value = normalizers.normalizeColor(value)
value = Color(value)
return value

def _set_base_color(self, value: ColorType) -> None:
def _set_base_color(self, value: QuadrupleCollectionType[IntFloatType]) -> None:
if value is not None:
value = normalizers.normalizeColor(value)
self._set_color(value)

def _get_color(self) -> ColorType: # type: ignore[return]
def _get_color(self) -> QuadrupleCollectionType[IntFloatType]: # type: ignore[return]
"""Get the color of the layer.

This is the environment implementation of
Expand All @@ -811,7 +811,9 @@ def _get_color(self) -> ColorType: # type: ignore[return]
"""
self.raiseNotImplementedError()

def _set_color(self, value: ColorType, **kwargs: Any) -> None:
def _set_color(
self, value: QuadrupleCollectionType[IntFloatType], **kwargs: Any
) -> None:
r"""Get or set the color of the layer.

This is the environment implementation of
Expand Down Expand Up @@ -979,7 +981,7 @@ def _autoUnicodes(self) -> None:

def interpolate(
self,
factor: FactorType,
factor: TransformationType,
minLayer: BaseLayer,
maxLayer: BaseLayer,
round: bool = True,
Expand Down Expand Up @@ -1036,7 +1038,7 @@ def interpolate(

def _interpolate(
self,
factor: FactorType,
factor: TransformationType,
minLayer: BaseLayer,
maxLayer: BaseLayer,
round: bool,
Expand Down
Loading