News for hackers. Stuff that matters.
Re:PEP 572: Python assignment expressions has been accepted by est on Tuesday July 03, 2018 @09:09AM (#17449827)
well, that looks easy.

    m = re.match(r1, s) or re.match(r2, s)
    o = m.group(1) if m else None
Re:PEP 572: Python assignment expressions has been accepted by cup-of-tea on Tuesday July 03, 2018 @09:20AM (#17449896)
I made a mistake in my question. The arguments to group shouldn't have been the same. What I want to get at is when the two branches are completely different code.
Re:PEP 572: Python assignment expressions has been accepted by est on Tuesday July 03, 2018 @09:04PM (#17454693)
I think it's a case where PEP 572 tries to fix bad library design.

re.match shouldn't return None at all. I often write helper functions like:

    matcher = lambda r, s: getattr(re.match(r, s), 'group', lambda i: '')
    o = matcher(r1, s)(1) or matcher(r2, s)(3)
here matcher have a fixed, static return type, string.