diff --git a/azure-pipelines.yml b/azure-pipelines.yml index cfd4f65dc775..5dce09e6d36b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -50,7 +50,7 @@ stages: strategy: matrix: Linux_py310: - vmImage: 'ubuntu-20.04' # keep one job pinned to the oldest image + vmImage: 'ubuntu-22.04' # keep one job pinned to the oldest image python.version: '3.10' Linux_py311: vmImage: 'ubuntu-latest' diff --git a/ci/mypy-stubtest-allowlist.txt b/ci/mypy-stubtest-allowlist.txt index 46ec06e0a9f1..85d9be15673e 100644 --- a/ci/mypy-stubtest-allowlist.txt +++ b/ci/mypy-stubtest-allowlist.txt @@ -28,7 +28,6 @@ matplotlib\.ticker\.LogitLocator\.nonsingular # Stdlib/Enum considered inconsistent (no fault of ours, I don't think) matplotlib\.backend_bases\._Mode\.__new__ -matplotlib\.units\.Number\.__hash__ # 3.6 Pending deprecations matplotlib\.figure\.Figure\.set_constrained_layout diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index cf35dc1de7db..50077c6738fa 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -331,20 +331,15 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag # Per-instance cache. self._get_info = functools.cache(self._get_info) # type: ignore[method-assign] self._fonts = {} - self.fontmap: dict[str | int, str] = {} + self.fontmap: dict[str, str] = {} filename = findfont(self.default_font_prop) default_font = get_font(filename) self._fonts['default'] = default_font self._fonts['regular'] = default_font - def _get_font(self, font: str | int) -> FT2Font: - if font in self.fontmap: - basename = self.fontmap[font] - else: - # NOTE: An int is only passed by subclasses which have placed int keys into - # `self.fontmap`, so we must cast this to confirm it to typing. - basename = T.cast(str, font) + def _get_font(self, font: str) -> FT2Font: + basename = self.fontmap.get(font, font) cached_font = self._fonts.get(basename) if cached_font is None and os.path.exists(basename): cached_font = get_font(basename) @@ -574,12 +569,13 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag # include STIX sized alternatives for glyphs if fallback is STIX if isinstance(self._fallback_font, StixFonts): stixsizedaltfonts = { - 0: 'STIXGeneral', - 1: 'STIXSizeOneSym', - 2: 'STIXSizeTwoSym', - 3: 'STIXSizeThreeSym', - 4: 'STIXSizeFourSym', - 5: 'STIXSizeFiveSym'} + '0': 'STIXGeneral', + '1': 'STIXSizeOneSym', + '2': 'STIXSizeTwoSym', + '3': 'STIXSizeThreeSym', + '4': 'STIXSizeFourSym', + '5': 'STIXSizeFiveSym', + } for size, name in stixsizedaltfonts.items(): fullpath = findfont(name) @@ -637,7 +633,7 @@ def _get_glyph(self, fontname: str, font_class: str, g = self._fallback_font._get_glyph(fontname, font_class, sym) family = g[0].family_name - if family in list(BakomaFonts._fontmap.values()): + if family in BakomaFonts._fontmap.values(): family = "Computer Modern" _log.info("Substituting symbol %s from %s", sym, family) return g @@ -658,13 +654,12 @@ def _get_glyph(self, fontname: str, font_class: str, def get_sized_alternatives_for_symbol(self, fontname: str, sym: str) -> list[tuple[str, str]]: if self._fallback_font: - return self._fallback_font.get_sized_alternatives_for_symbol( - fontname, sym) + return self._fallback_font.get_sized_alternatives_for_symbol(fontname, sym) return [(fontname, sym)] class DejaVuFonts(UnicodeFonts, metaclass=abc.ABCMeta): - _fontmap: dict[str | int, str] = {} + _fontmap: dict[str, str] = {} def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlags): # This must come first so the backend's owner is set correctly @@ -676,11 +671,11 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag TruetypeFonts.__init__(self, default_font_prop, load_glyph_flags) # Include Stix sized alternatives for glyphs self._fontmap.update({ - 1: 'STIXSizeOneSym', - 2: 'STIXSizeTwoSym', - 3: 'STIXSizeThreeSym', - 4: 'STIXSizeFourSym', - 5: 'STIXSizeFiveSym', + '1': 'STIXSizeOneSym', + '2': 'STIXSizeTwoSym', + '3': 'STIXSizeThreeSym', + '4': 'STIXSizeFourSym', + '5': 'STIXSizeFiveSym', }) for key, name in self._fontmap.items(): fullpath = findfont(name) @@ -718,7 +713,7 @@ class DejaVuSerifFonts(DejaVuFonts): 'sf': 'DejaVu Sans', 'tt': 'DejaVu Sans Mono', 'ex': 'DejaVu Serif Display', - 0: 'DejaVu Serif', + '0': 'DejaVu Serif', } @@ -736,7 +731,7 @@ class DejaVuSansFonts(DejaVuFonts): 'sf': 'DejaVu Sans', 'tt': 'DejaVu Sans Mono', 'ex': 'DejaVu Sans Display', - 0: 'DejaVu Sans', + '0': 'DejaVu Sans', } @@ -752,7 +747,7 @@ class StixFonts(UnicodeFonts): - handles sized alternative characters for the STIXSizeX fonts. """ - _fontmap: dict[str | int, str] = { + _fontmap = { 'rm': 'STIXGeneral', 'it': 'STIXGeneral:italic', 'bf': 'STIXGeneral:weight=bold', @@ -760,12 +755,12 @@ class StixFonts(UnicodeFonts): 'nonunirm': 'STIXNonUnicode', 'nonuniit': 'STIXNonUnicode:italic', 'nonunibf': 'STIXNonUnicode:weight=bold', - 0: 'STIXGeneral', - 1: 'STIXSizeOneSym', - 2: 'STIXSizeTwoSym', - 3: 'STIXSizeThreeSym', - 4: 'STIXSizeFourSym', - 5: 'STIXSizeFiveSym', + '0': 'STIXGeneral', + '1': 'STIXSizeOneSym', + '2': 'STIXSizeTwoSym', + '3': 'STIXSizeThreeSym', + '4': 'STIXSizeFourSym', + '5': 'STIXSizeFiveSym', } _fallback_font = None _sans = False @@ -832,10 +827,8 @@ def _map_virtual_font(self, fontname: str, font_class: str, return fontname, uniindex @functools.cache - def get_sized_alternatives_for_symbol( # type: ignore[override] - self, - fontname: str, - sym: str) -> list[tuple[str, str]] | list[tuple[int, str]]: + def get_sized_alternatives_for_symbol(self, fontname: str, + sym: str) -> list[tuple[str, str]]: fixes = { '\\{': '{', '\\}': '}', '\\[': '[', '\\]': ']', '<': '\N{MATHEMATICAL LEFT ANGLE BRACKET}', @@ -846,8 +839,8 @@ def get_sized_alternatives_for_symbol( # type: ignore[override] uniindex = get_unicode_index(sym) except ValueError: return [(fontname, sym)] - alternatives = [(i, chr(uniindex)) for i in range(6) - if self._get_font(i).get_char_index(uniindex) != 0] + alternatives = [(str(i), chr(uniindex)) for i in range(6) + if self._get_font(str(i)).get_char_index(uniindex) != 0] # The largest size of the radical symbol in STIX has incorrect # metrics that cause it to be disconnected from the stem. if sym == r'\__sqrt__': @@ -1542,7 +1535,7 @@ def __init__(self, c: str, height: float, depth: float, state: ParserState, break shift = 0.0 - if state.font != 0 or len(alternatives) == 1: + if state.font != '0' or len(alternatives) == 1: if factor is None: factor = target_total / (char.height + char.depth) state.fontsize *= factor @@ -2530,7 +2523,7 @@ def subsuper(self, s: str, loc: int, toks: ParseResults) -> T.Any: # Handle regular sub/superscripts constants = _get_font_constant_set(state) lc_height = last_char.height - lc_baseline = 0 + lc_baseline = 0.0 if self.is_dropsub(last_char): lc_baseline = last_char.depth diff --git a/lib/matplotlib/ft2font.pyi b/lib/matplotlib/ft2font.pyi index 37281afeaafa..3c8b52a73b6b 100644 --- a/lib/matplotlib/ft2font.pyi +++ b/lib/matplotlib/ft2font.pyi @@ -194,7 +194,7 @@ class FT2Font(Buffer): _kerning_factor: int = ... ) -> None: ... if sys.version_info[:2] >= (3, 12): - def __buffer__(self, flags: int) -> memoryview: ... + def __buffer__(self, /, flags: int) -> memoryview: ... def _get_fontmap(self, string: str) -> dict[str, FT2Font]: ... def clear(self) -> None: ... def draw_glyph_to_bitmap( @@ -286,7 +286,7 @@ class FT2Image(Buffer): def __init__(self, width: int, height: int) -> None: ... def draw_rect_filled(self, x0: int, y0: int, x1: int, y1: int) -> None: ... if sys.version_info[:2] >= (3, 12): - def __buffer__(self, flags: int) -> memoryview: ... + def __buffer__(self, /, flags: int) -> memoryview: ... @final class Glyph: