def bump_version(version, which=None):
try:<EOL><INDENT>parts = [int(n) for n in version.split('<STR_LIT:.>')]<EOL><DEDENT>except ValueError:<EOL><INDENT>fail('<STR_LIT>')<EOL><DEDENT>if len(parts) != <NUM_LIT:3>:<EOL><INDENT>fail('<STR_LIT>')<EOL><DEDENT>PARTS = {'<STR_LIT>': <NUM_LIT:0>, '<STR_LIT>': <NUM_LIT:1>, '<STR_LIT>': <NUM_LIT:2>}<EOL>index = PARTS[which] if which in PARTS else <NUM_LIT:2><EOL>before, middle, after = parts[:index], parts[index], parts[index + <NUM_LIT:1>:]<EOL>middle += <NUM_LIT:1><EOL>return '<STR_LIT:.>'.join(str(n) for n in before + [middle] + after)<EOL>
Returns the result of incrementing `version`.

    If `which` is not specified, the "patch" part of the version number will be
    incremented.  If `which` is specified, it must be ``'major'``, ``'minor'``,
    or ``'patch'``. If it is one of these three strings, the corresponding part
    of the version number will be incremented instead of the patch number.

    Returns a string representing the next version number.

    Example::

        >>> bump_version('2.7.1')
        '2.7.2'
        >>> bump_version('2.7.1', 'minor')
        '2.8.0'
        >>> bump_version('2.7.1', 'major')
        '3.0.0'