Skip to content

[MNT]: UserWarning from pyparsing upon immediate import #24972

Closed

Description

@greglucas

Summary

An immediate userwarning on import:

python -W always -c "import matplotlib"

lib/matplotlib/_fontconfig_pattern.py:71: UserWarning: warn_multiple_tokens_in_named_alternation: setting results name 'properties*' on MatchFirst expression will return a list of all parsed tokens in an And alternative, in prior versions only the first token was returned; enclose contained argument in Group

The pyparsing version installed is 3.0.9

Proposed fix

No response

Activity

  1. added this to the v3.7.0 milestone on Jan 13, 2023
  2. anntzer commented on Jan 14, 2023

    @anntzer
    Contributor

    Looks like this just needs what the warning says:

    diff --git i/lib/matplotlib/_fontconfig_pattern.py w/lib/matplotlib/_fontconfig_pattern.py
    index efc1c9304f..f0ed155c2d 100644
    --- i/lib/matplotlib/_fontconfig_pattern.py
    +++ w/lib/matplotlib/_fontconfig_pattern.py
    @@ -13,7 +13,7 @@ from functools import lru_cache, partial
     import re
     
     from pyparsing import (
    -    Optional, ParseException, Regex, StringEnd, Suppress, ZeroOrMore)
    +    Group, Optional, ParseException, Regex, StringEnd, Suppress, ZeroOrMore)
     
     from matplotlib import _api
     
    @@ -64,7 +64,7 @@ def _make_fontconfig_parser():
         name = Regex(r"[a-z]+")
         value = Regex(r"([^%s]|(\\[%s]))*" % (_value_punc, _value_punc))
         # replace trailing `| name` by oneOf(_CONSTANTS) in mpl 3.9.
    -    prop = (name + Suppress("=") + comma_separated(value)) | name
    +    prop = Group((name + Suppress("=") + comma_separated(value)) | name)
         return (
             Optional(comma_separated(family)("families"))
             + Optional("-" + comma_separated(size)("sizes"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions