[MNT]: Remove macOS 10.12 compatibility from ft2font_wrapper · Issue #31963 · matplotlib/matplotlib · GitHub
Skip to content

[MNT]: Remove macOS 10.12 compatibility from ft2font_wrapper #31963

Description

@iccir

Summary

There are several comments in ft2font_wrapper.cpp related to macOS 10.12 compatibility:

FT2Font::LanguageType languages;
if (auto value = std::get_if<FT2Font::LanguageType>(&languages_or_str)) {
    languages = std::move(*value);
} else if (auto value = std::get_if<std::string>(&languages_or_str)) {
    languages = std::vector<FT2Font::LanguageRange>{
        FT2Font::LanguageRange{*value, 0, text.size()}
    };
} else {
    // NOTE: this can never happen as pybind11 would have checked the type in the
    // Python wrapper before calling this function, but we need to keep the
    // std::get_if instead of std::get for macOS 10.12 compatibility.
    throw py::type_error("languages must be str or list of tuple");
}

Since the ARC changes in PR #31855 requires macOS 10.14 or later, I believe that the above logic can be simplified.

My knowledge of the C++ std is very limited, Claude suggests using std::holds_alternative:

FT2Font::LanguageType languages;
if (std::holds_alternative<FT2Font::LanguageType>(languages_or_str)) {
    languages = std::move(std::get<FT2Font::LanguageType>(languages_or_str));
} else {
    languages = std::vector<FT2Font::LanguageRange>{
        FT2Font::LanguageRange{std::get<std::string>(languages_or_str), 0, text.size()}
    };
}

I'm happy to do this cleanup and submit a PR if someone with C++ knowledge can give guidance!

Proposed fix

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions