Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix re pattern pretty print#14558

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
wimglenn wants to merge1 commit intoipython:mainfromwimglenn:patch-1
Closed

Conversation

wimglenn
Copy link
Contributor

@wimglennwimglenn commentedOct 24, 2024
edited
Loading

re.TEMPLATE is gone in Python 3.13 resulting in a crash in the pattern pretty printer

Reproducer:

>>> import re>>> re.compile("")
Click me to see the traceback!
---------------------------------------------------------------------------AttributeError                            Traceback (most recent call last)File ~/.local/lib/python3.13/site-packages/IPython/core/formatters.py:711, in PlainTextFormatter.__call__(self, obj)    704 stream = StringIO()    705 printer = pretty.RepresentationPrinter(stream, self.verbose,    706     self.max_width, self.newline,    707     max_seq_length=self.max_seq_length,    708     singleton_pprinters=self.singleton_printers,    709     type_pprinters=self.type_printers,    710     deferred_pprinters=self.deferred_printers)--> 711 printer.pretty(obj)    712 printer.flush()    713 return stream.getvalue()File ~/.local/lib/python3.13/site-packages/IPython/lib/pretty.py:394, in RepresentationPrinter.pretty(self, obj)    391 for cls in _get_mro(obj_class):    392     if cls in self.type_pprinters:    393         # printer registered in self.type_pprinters--> 394         return self.type_pprinters[cls](obj, self, cycle)    395     else:    396         # deferred printer    397         printer = self._in_deferred_types(cls)File ~/.local/lib/python3.13/site-packages/IPython/lib/pretty.py:740, in _re_pattern_pprint(obj, p, cycle)    738 re_compile = CallExpression.factory('re.compile')    739 if obj.flags:--> 740     p.pretty(re_compile(RawStringLiteral(obj.pattern), _ReFlags(obj.flags)))    741 else:    742     p.pretty(re_compile(RawStringLiteral(obj.pattern)))File ~/.local/lib/python3.13/site-packages/IPython/lib/pretty.py:408, in RepresentationPrinter.pretty(self, obj)    406     meth = cls._repr_pretty_    407     if callable(meth):--> 408         return meth(obj, self, cycle)    409 if (    410     cls is not object    411     # check if cls defines __repr__   (...)    417     and callable(_safe_getattr(cls, "__repr__", None))    418 ):    419     return _repr_pprint(obj, self, cycle)File ~/.local/lib/python3.13/site-packages/IPython/lib/pretty.py:573, in CallExpression._repr_pretty_(self, p, cycle)    571 for arg in self.args:    572     new_item()--> 573     p.pretty(arg)    574 for arg_name, arg in self.kwargs.items():    575     new_item()File ~/.local/lib/python3.13/site-packages/IPython/lib/pretty.py:408, in RepresentationPrinter.pretty(self, obj)    406     meth = cls._repr_pretty_    407     if callable(meth):--> 408         return meth(obj, self, cycle)    409 if (    410     cls is not object    411     # check if cls defines __repr__   (...)    417     and callable(_safe_getattr(cls, "__repr__", None))    418 ):    419     return _repr_pprint(obj, self, cycle)File ~/.local/lib/python3.13/site-packages/IPython/lib/pretty.py:729, in _ReFlags._repr_pretty_(self, p, cycle)    726 done_one = False    727 for flag in ('TEMPLATE', 'IGNORECASE', 'LOCALE', 'MULTILINE', 'DOTALL',    728     'UNICODE', 'VERBOSE', 'DEBUG'):--> 729     if self.value & getattr(re, flag):    730         if done_one:    731             p.text('|')AttributeError: module 're' has no attribute 'TEMPLATE'

Apparently it was "undocumented and never working" (#32300). That was reverted and then usage deprecated immediately in#93161.

Status of existingre.TEMPLATE attribute in currently supported Python versions for IPython:

Since 3.11, using it in the first place causes warnings:

$ python3.11 -WallPython 3.11.10 (main, Oct 16 2024, 10:51:55) [GCC 12.2.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import re>>> re.compile("", flags=re.TEMPLATE).../Python-3.11.10/lib/python3.11/re/__init__.py:289: DeprecationWarning: The re.TEMPLATE/re.T flag is deprecated as it is an undocumented flag without an obvious purpose. Don't use it.  warnings.warn("The re.TEMPLATE/re.T flag is deprecated "re.compile('', re.TEMPLATE)

#14559 offers an alternative approach, but it will change the pretty-print result for 3.10-3.12, I'm not sure if that would be considered a backwards-compatibility breaking change.

wimglenn added a commit to wimglenn/ipython that referenced this pull requestOct 24, 2024
Carreau added a commit that referenced this pull requestOct 25, 2024
@Carreau
Copy link
Member

closing as I merged your#14559 alternative. Thanks.

@CarreauCarreau added this to the8.29 milestoneOct 25, 2024
@wimglennwimglenn deleted the patch-1 branchOctober 25, 2024 17:24
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
8.29
Development

Successfully merging this pull request may close these issues.

2 participants
@wimglenn@Carreau

[8]ページ先頭

©2009-2025 Movatter.jp