# Buggy code
def to_int(s):
    # We must be able to handle octal representation for `mode` values notably
    if six.PY3 and re.match("^0[0-9]+$", s.strip()):
        s = "0o" + s[1:]
    return int(s, base=0)


# Traceback (ValueError)
$ docker-compose pull
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 11, in <module>
load_entry_point('docker-compose==1.18.0', 'console_scripts', 'docker-compose')()
File "/usr/lib/python3.6/site-packages/compose/cli/main.py", line 71, in main
command()
File "/usr/lib/python3.6/site-packages/compose/cli/main.py", line 121, in perform_command
project = project_from_options('.', options)
File "/usr/lib/python3.6/site-packages/compose/cli/command.py", line 37, in project_from_options
override_dir=options.get('--project-directory'),
File "/usr/lib/python3.6/site-packages/compose/cli/command.py", line 91, in get_project
config_data = config.load(config_details)
File "/usr/lib/python3.6/site-packages/compose/config/config.py", line 375, in load
for config_file in config_details.config_files
File "/usr/lib/python3.6/site-packages/compose/config/config.py", line 375, in <listcomp>
for config_file in config_details.config_files
File "/usr/lib/python3.6/site-packages/compose/config/config.py", line 506, in process_config_file
environment)
File "/usr/lib/python3.6/site-packages/compose/config/config.py", line 497, in interpolate_config_section
environment
File "/usr/lib/python3.6/site-packages/compose/config/interpolation.py", line 44, in interpolate_environment_variables
for name, config_dict in config.items()
File "/usr/lib/python3.6/site-packages/compose/config/interpolation.py", line 44, in <genexpr>
for name, config_dict in config.items()
File "/usr/lib/python3.6/site-packages/compose/config/interpolation.py", line 39, in process_item
for key, val in (config_dict or {}).items()
File "/usr/lib/python3.6/site-packages/compose/config/interpolation.py", line 39, in <genexpr>
for key, val in (config_dict or {}).items()
File "/usr/lib/python3.6/site-packages/compose/config/interpolation.py", line 54, in interpolate_value
return recursive_interpolate(value, interpolator, get_config_path(config_key, section, name))
File "/usr/lib/python3.6/site-packages/compose/config/interpolation.py", line 74, in recursive_interpolate
for (key, val) in obj.items()
File "/usr/lib/python3.6/site-packages/compose/config/interpolation.py", line 74, in <genexpr>
for (key, val) in obj.items()
File "/usr/lib/python3.6/site-packages/compose/config/interpolation.py", line 70, in recursive_interpolate
return converter.convert(config_path, interpolator.interpolate(obj))
File "/usr/lib/python3.6/site-packages/compose/config/interpolation.py", line 184, in convert
return self.map[rexp](value)
File "/usr/lib/python3.6/site-packages/compose/config/interpolation.py", line 141, in to_int
return int(s, base=0)
ValueError: invalid literal for int() with base 0: '1g'

# Fixed code
def to_int(s):
    # We must be able to handle octal representation for `mode` values notably
    if six.PY3 and re.match("^0[0-9]+$", s.strip()):
        s = "0o" + s[1:]
    try:
        return int(s, base=0)
    except ValueError:
        raise ValueError('"{}" is not a valid integer'.format(s))