Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some RegexFlag cannot be printed in the repr #89092

Closed
pablogsal opened this issue Aug 16, 2021 · 8 comments
Closed

Some RegexFlag cannot be printed in the repr #89092

pablogsal opened this issue Aug 16, 2021 · 8 comments
Labels
3.11 only security fixes

Comments

@pablogsal
Copy link
Member

BPO 44929
Nosy @ethanfurman, @ambv, @pablogsal
PRs
  • bpo-44929: Fix enum string representation in the REPL #27789
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-08-27.10:09:44.917>
    created_at = <Date 2021-08-16.22:03:59.743>
    labels = ['3.11']
    title = 'Some RegexFlag cannot be printed in the repr'
    updated_at = <Date 2021-08-27.10:09:44.917>
    user = 'https://github.com/pablogsal'

    bugs.python.org fields:

    activity = <Date 2021-08-27.10:09:44.917>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-08-27.10:09:44.917>
    closer = 'lukasz.langa'
    components = []
    creation = <Date 2021-08-16.22:03:59.743>
    creator = 'pablogsal'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44929
    keywords = ['patch']
    message_count = 8.0
    messages = ['399688', '399690', '399691', '399692', '399827', '399863', '400271', '400408']
    nosy_count = 3.0
    nosy_names = ['ethan.furman', 'lukasz.langa', 'pablogsal']
    pr_nums = ['27789']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44929'
    versions = ['Python 3.11']

    @pablogsal
    Copy link
    Member Author

    When printing some instance of RegexFlag **in the REPL** it fails to print:

    >>> import gc
    # This prints a ton of objects, including the bad enum RegexFlag one
    >>> gc.get_referrers(None) 
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/pablogsal/github/cpython/Lib/enum.py", line 1399, in global_flag_repr
        return "%x" % (module, cls_name, self._value_)
               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    TypeError: %x format: an integer is required, not str

    @pablogsal pablogsal added 3.10 only security fixes 3.11 only security fixes labels Aug 16, 2021
    @pablogsal
    Copy link
    Member Author

    (Deleted last message because it was incorrect)

    @pablogsal
    Copy link
    Member Author

    Simpler reproducer:

    >>> import re
    >>> re.RegexFlag(0)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/pablogsal/github/cpython/Lib/enum.py", line 1399, in global_flag_repr
        return "%x" % (module, cls_name, self._value_)
               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    TypeError: %x format: an integer is required, not str

    @pablogsal
    Copy link
    Member Author

    This looks incorrect:

    return "%x" % (module, cls_name, self._value_)

    @ambv
    Copy link
    Contributor

    ambv commented Aug 18, 2021

    Ethan, could you take a look at the PR? I added a few failing test methods since repr handling for global enum flags wasn't covered and looks unfinished. If you tell us what the expected return values should be, I'll finish the fix.

    @ethanfurman
    Copy link
    Member

    _name_ is only None if the entire enum value is outside any named member and _boundary_ is KEEP -- so

        class Example(Flag, boundary=KEEP):
            first = auto()
            second = auto()
            third = auto()
        >>> Example(0)
        module.Example(0)
    
        >>> Example(8)
        module.Example(8)

    No need to backport.

    @ethanfurman ethanfurman removed 3.10 only security fixes labels Aug 18, 2021
    @ethanfurman
    Copy link
    Member

    New changeset 24da544 by Pablo Galindo Salgado in branch 'main':
    bpo-44929: [Enum] Fix global repr (GH-27789)
    24da544

    @ambv
    Copy link
    Contributor

    ambv commented Aug 27, 2021

    repr(re.RegexFlag(0)) no longer crashes so we can close this.

    @ambv ambv closed this as completed Aug 27, 2021
    @ambv ambv closed this as completed Aug 27, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants