Resolving multiple "paths" in nested attributes
What do you think this will return for part = '[compact|fullsize|x|y]'


re.findall(r'\[(\w+)(?:\|(\w+))*\]', part)



It will give:


[('compact', 'y')]



Because, when a group matches multiple times, the last match overwrites previous matches, as per the docs.
If you want to support multiple patterns, I'm afraid you will have to do in two steps: matching and then splitting.



The part I don't like about this is that you split path to parts,
then when you need to recurse,
you re-join the parts again,
and in the recursion step it will be split again, and so on.
That's a lot of splitting and joining and iterations.
The recursive logic can be also tricky to understand.

Here's an alternative, without using recursion and unnecessary splitting, joining, iteration:

from collections import deque


def resolve_paths(path):
    parts = deque(path.split('.'))
    paths = [[]]

    while parts:
        part = parts.popleft()
        branches = re.findall(r'\[(\w+)(?:\|(\w+))*\]', part)
        if branches:
            orig_paths = paths[:]
            paths = []
            for branch in branches[0]:
                for path in orig_paths:
                    paths.append(path + [branch])
        else:
            for path in paths:
                path.append(part)

    return ['.'.join(path) for path in paths]