Skip to content

Must import sre_constants to catch re.compile errors. #39129

Description

@jemfinch
mannequin
BPO 795379

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 2003-08-26.17:10:05.000>
created_at = <Date 2003-08-26.14:19:27.000>
labels = ['expert-regex']
title = 'Must import sre_constants to catch re.compile errors.'
updated_at = <Date 2003-08-26.17:10:05.000>
user = 'https://bugs.python.org/jemfinch'

bugs.python.org fields:

activity = <Date 2003-08-26.17:10:05.000>
actor = 'jemfinch'
assignee = 'effbot'
closed = True
closed_date = None
closer = None
components = ['Regular Expressions']
creation = <Date 2003-08-26.14:19:27.000>
creator = 'jemfinch'
dependencies = []
files = []
hgrepos = []
issue_num = 795379
keywords = []
message_count = 3.0
messages = ['17954', '17955', '17956']
nosy_count = 2.0
nosy_names = ['effbot', 'jemfinch']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue795379'
versions = []

Activity

  1. jemfinch commented on Aug 26, 2003

    jemfinchmannequin
    MannequinAuthor

    It's a bit frustrating not to be able to catch
    exceptions raised by re.compile with just the re
    module. The fact that sre_constants.error is
    raised is a bit too much implementation showing
    through, IMO.

    Anyway, I suggest a exception be added to the re
    module that subclasses sre_constants.error for
    backwards compatibility. So users can simply
    import re and catch re.error instead of having to
    import re and sre_constants and catch
    sre_constants.error.

  2. effbot commented on Aug 26, 2003

    effbotmannequin
    Mannequin

    Logged In: YES
    user_id=38376

    afaik, the following has worked since 1.6, and still works
    in 2.3:

    >>> import re
    >>> try:
    ...     re.compile("[]*")
    ... except re.error:
    ...     print "oops"
    ...
    oops

    what Python version are you using?

  3. jemfinch commented on Aug 26, 2003

    jemfinchmannequin
    MannequinAuthor

    Logged In: YES
    user_id=99508

    Oops, my fault.

  4. transferred this issue fromon Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions