Skip to content

Commit

Permalink
fix UFOFormatVersion tuple's __str__ in python 3.11
Browse files Browse the repository at this point in the history
python 3.11 doesn't like when a mixin overrides a dunder method like __str__, for some reasons it keep using Enum.__str__, see
#2655
  • Loading branch information
anthrotype committed Jul 6, 2022
1 parent ce38db6 commit 5ca5791
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Lib/fontTools/ufoLib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class UFOFormatVersion(tuple, _VersionTupleEnumMixin, enum.Enum):
FORMAT_2_0 = (2, 0)
FORMAT_3_0 = (3, 0)

# python 3.11 doesn't like when a mixin overrides a dunder method like __str__
# for some reasons it keep using Enum.__str__, see
# https://github.com/fonttools/fonttools/pull/2655
UFOFormatVersion.__str__ = _VersionTupleEnumMixin.__str__


class UFOFileStructure(enum.Enum):
ZIP = "zip"
Expand Down
3 changes: 3 additions & 0 deletions Lib/fontTools/ufoLib/glifLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def supported_versions(cls, ufoFormatVersion=None):
versions.add(cls.FORMAT_2_0)
return frozenset(versions)

# workaround for py3.11, see https://github.com/fonttools/fonttools/pull/2655
GLIFFormatVersion.__str__ = _VersionTupleEnumMixin.__str__


# ------------
# Simple Glyph
Expand Down

5 comments on commit 5ca5791

@justvanrossum
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a bug in 3.11? It is a rather unexpected incompatibility.

@anthrotype
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea.. yeah, we could file a bug. I don't have time right now. Or feel free to do it, thanks

@justvanrossum
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justvanrossum
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upstream 3.11 issue has apparently been resolved: python/cpython#94601

@anthrotype
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good! I guess we can keep the hack for a bit until things will settle

Please sign in to comment.