Skip to content

Excessive patterns when range starts with 0 #6

@achemichev

Description

@achemichev

Such a test is desired:

self.assertEqual(regex_for_range(100, 201), r'1\d{2}|20[0-1]')`

My suggestion is to remove some excessive stops inside while loops of split_to_ranges (new lines marked with <<):

def split_to_ranges(min_, max_):
    ...
    while min_ <= stop < max_:
        if str(stop).replace('9', '0') == str(min_):        """ << """
            stops = set(filter(lambda x: x >= stop, stops)) """ << """
        stops.add(stop)
        ...
    ...
    while min_ < stop <= max_:
        if str(stop).replace('9', '0') == str(min_):        """ << """
            stops = set(filter(lambda x: x >= stop, stops)) """ << """
        stops.add(stop)
        ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions