Skip to content

Commit

Permalink
Merge pull request #179 from fonttools/housekeeping
Browse files Browse the repository at this point in the history
Housekeeping
  • Loading branch information
madig authored Nov 9, 2021
2 parents 2cbd725 + e10ef17 commit 1ee46af
Show file tree
Hide file tree
Showing 33 changed files with 482 additions and 439 deletions.
6 changes: 5 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[mypy]
python_version = 3.6
python_version = 3.7

# Untyped definitions and calls
disallow_incomplete_defs = True
Expand All @@ -19,6 +19,10 @@ strict_equality = True
[mypy-ufoLib2.*]
disallow_untyped_defs = True

[mypy-ufoLib2._version]
# Unavailable until package installation.
ignore_missing_imports = True

[mypy-fontTools.*]
ignore_missing_imports = True

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"]
build-backend = "setuptools.build_meta"

[tool.black]
target-version = ["py36"]
target-version = ["py37"]

[tool.isort]
multi_line_output = 3
Expand Down
4 changes: 3 additions & 1 deletion src/ufoLib2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""ufoLib2 -- a package for dealing with UFO fonts."""

from __future__ import annotations

from ufoLib2.objects import Font

try:
from ._version import version as __version__ # type: ignore
from ._version import version as __version__
except ImportError:
__version__ = "0.0.0+unknown"

Expand Down
2 changes: 2 additions & 0 deletions src/ufoLib2/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

DEFAULT_LAYER_NAME: str = "public.default"
"""The name of the default layer."""

Expand Down
3 changes: 3 additions & 0 deletions src/ufoLib2/errors.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from __future__ import annotations


class Error(Exception):
"""The base exception for ufoLib2."""
2 changes: 2 additions & 0 deletions src/ufoLib2/objects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ufoLib2.objects.anchor import Anchor
from ufoLib2.objects.component import Component
from ufoLib2.objects.contour import Contour
Expand Down
10 changes: 5 additions & 5 deletions src/ufoLib2/objects/anchor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Tuple
from __future__ import annotations

from attr import define

Expand All @@ -18,16 +18,16 @@ class Anchor(AttrDictMixin):
y: float
"""The y coordinate of the anchor."""

name: Optional[str] = None
name: str | None = None
"""The name of the anchor."""

color: Optional[str] = None
color: str | None = None
"""The color of the anchor."""

identifier: Optional[str] = None
identifier: str | None = None
"""The globally unique identifier of the anchor."""

def move(self, delta: Tuple[float, float]) -> None:
def move(self, delta: tuple[float, float]) -> None:
"""Moves anchor by (x, y) font units."""
x, y = delta
self.x += x
Expand Down
11 changes: 6 additions & 5 deletions src/ufoLib2/objects/component.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from typing import Optional, Tuple

from attr import define, field
from fontTools.misc.transform import Identity, Transform
Expand Down Expand Up @@ -29,10 +30,10 @@ class Component:
transformation: Transform = field(default=Identity, converter=_convert_transform)
"""The affine transformation to apply to the :attr:`.Component.baseGlyph`."""

identifier: Optional[str] = None
identifier: str | None = None
"""The globally unique identifier of the component."""

def move(self, delta: Tuple[float, float]) -> None:
def move(self, delta: tuple[float, float]) -> None:
"""Moves this component by (x, y) font units.
NOTE: This interprets the delta to be the visual delta, as in, it
Expand All @@ -47,7 +48,7 @@ def move(self, delta: Tuple[float, float]) -> None:
xx, xy, yx, yy, dx, dy = self.transformation
self.transformation = Transform(xx, xy, yx, yy, dx + x, dy + y)

def getBounds(self, layer: GlyphSet) -> Optional[BoundingBox]:
def getBounds(self, layer: GlyphSet) -> BoundingBox | None:
"""Returns the (xMin, yMin, xMax, yMax) bounding box of the component,
taking the actual contours into account.
Expand All @@ -56,7 +57,7 @@ def getBounds(self, layer: GlyphSet) -> Optional[BoundingBox]:
"""
return getBounds(self, layer)

def getControlBounds(self, layer: GlyphSet) -> Optional[BoundingBox]:
def getControlBounds(self, layer: GlyphSet) -> BoundingBox | None:
"""Returns the (xMin, yMin, xMax, yMax) bounding box of the component,
taking only the control points into account.
Expand Down
38 changes: 21 additions & 17 deletions src/ufoLib2/objects/contour.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import warnings
from collections.abc import MutableSequence
from typing import Iterable, Iterator, List, Optional, Tuple, Union, overload
from typing import TYPE_CHECKING, Iterable, Iterator, overload

from attr import define, field
from fontTools.pens.basePen import AbstractPen
Expand All @@ -10,9 +12,15 @@
from ufoLib2.objects.point import Point
from ufoLib2.typing import GlyphSet

# For Python 3.7 compatibility.
if TYPE_CHECKING:
ContourMapping = MutableSequence[Point]
else:
ContourMapping = MutableSequence


@define
class Contour(MutableSequence):
class Contour(ContourMapping):
"""Represents a contour as a list of points.
Behavior:
Expand All @@ -39,32 +47,30 @@ class Contour(MutableSequence):
contour[0] = anotherPoint
"""

points: List[Point] = field(factory=list)
points: list[Point] = field(factory=list)
"""The list of points in the contour."""

identifier: Optional[str] = field(default=None, repr=False)
identifier: str | None = field(default=None, repr=False)
"""The globally unique identifier of the contour."""

# collections.abc.MutableSequence interface

def __delitem__(self, index: Union[int, slice]) -> None:
def __delitem__(self, index: int | slice) -> None:
del self.points[index]

@overload
def __getitem__(self, index: int) -> Point:
...

@overload
def __getitem__(self, index: slice) -> List[Point]: # noqa: F811
def __getitem__(self, index: slice) -> list[Point]: # noqa: F811
...

def __getitem__( # noqa: F811
self, index: Union[int, slice]
) -> Union[Point, List[Point]]:
def __getitem__(self, index: int | slice) -> Point | list[Point]: # noqa: F811
return self.points[index]

def __setitem__( # noqa: F811
self, index: Union[int, slice], point: Union[Point, Iterable[Point]]
self, index: int | slice, point: Point | Iterable[Point]
) -> None:
if isinstance(index, int) and isinstance(point, Point):
self.points[index] = point
Expand Down Expand Up @@ -100,12 +106,12 @@ def open(self) -> bool:
return True
return self.points[0].type == "move"

def move(self, delta: Tuple[float, float]) -> None:
def move(self, delta: tuple[float, float]) -> None:
"""Moves contour by (x, y) font units."""
for point in self.points:
point.move(delta)

def getBounds(self, layer: Optional[GlyphSet] = None) -> Optional[BoundingBox]:
def getBounds(self, layer: GlyphSet | None = None) -> BoundingBox | None:
"""Returns the (xMin, yMin, xMax, yMax) bounding box of the glyph,
taking the actual contours into account.
Expand All @@ -115,17 +121,15 @@ def getBounds(self, layer: Optional[GlyphSet] = None) -> Optional[BoundingBox]:
return getBounds(self, layer)

@property
def bounds(self) -> Optional[BoundingBox]:
def bounds(self) -> BoundingBox | None:
"""Returns the (xMin, yMin, xMax, yMax) bounding box of the glyph,
taking the actual contours into account.
|defcon_compat|
"""
return self.getBounds()

def getControlBounds(
self, layer: Optional[GlyphSet] = None
) -> Optional[BoundingBox]:
def getControlBounds(self, layer: GlyphSet | None = None) -> BoundingBox | None:
"""Returns the (xMin, yMin, xMax, yMax) bounding box of the glyph,
taking only the control points into account.
Expand All @@ -135,7 +139,7 @@ def getControlBounds(
return getControlBounds(self, layer)

@property
def controlPointBounds(self) -> Optional[BoundingBox]:
def controlPointBounds(self) -> BoundingBox | None:
"""Returns the (xMin, yMin, xMax, yMax) bounding box of the glyph,
taking only the control points into account.
Expand Down
8 changes: 4 additions & 4 deletions src/ufoLib2/objects/dataSet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations

from fontTools.ufoLib import UFOReader, UFOWriter

Expand All @@ -25,14 +25,14 @@ class DataSet(DataStore):
"""

@staticmethod
def list_contents(reader: UFOReader) -> List[str]:
def list_contents(reader: UFOReader) -> list[str]:
"""Returns a list of POSIX filename strings in the data store."""
return reader.getDataDirectoryListing()
return reader.getDataDirectoryListing() # type: ignore

@staticmethod
def read_data(reader: UFOReader, filename: str) -> bytes:
"""Returns the data at filename within the store."""
return reader.readData(filename)
return reader.readData(filename) # type: ignore

@staticmethod
def write_data(writer: UFOWriter, filename: str, data: bytes) -> None:
Expand Down
2 changes: 2 additions & 0 deletions src/ufoLib2/objects/features.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from attr import define


Expand Down
Loading

0 comments on commit 1ee46af

Please sign in to comment.