Skip to content

UnboundLocalError when combining allow_dash and dir_okay #551

@DRMacIver

Description

@DRMacIver
import click

@click.command()
@click.argument('filename', type=click.Path(dir_okay=False, allow_dash=True))
def foo(filename):
    pass

if __name__ == '__main__':
    foo()

When this script is invoked with the argument '-' I see the following error:

  File "boo.py", line 10, in <module>
    foo()
  File "/home/david/projects/structureshrink/foo/lib/python3.5/site-packages/click-6.4-py3.5.egg/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/home/david/projects/structureshrink/foo/lib/python3.5/site-packages/click-6.4-py3.5.egg/click/core.py", line 695, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/home/david/projects/structureshrink/foo/lib/python3.5/site-packages/click-6.4-py3.5.egg/click/core.py", line 620, in make_context
    self.parse_args(ctx, args)
  File "/home/david/projects/structureshrink/foo/lib/python3.5/site-packages/click-6.4-py3.5.egg/click/core.py", line 874, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "/home/david/projects/structureshrink/foo/lib/python3.5/site-packages/click-6.4-py3.5.egg/click/core.py", line 1390, in handle_parse_result
    value = self.full_process_value(ctx, value)
  File "/home/david/projects/structureshrink/foo/lib/python3.5/site-packages/click-6.4-py3.5.egg/click/core.py", line 1359, in full_process_value
    value = self.process_value(ctx, value)
  File "/home/david/projects/structureshrink/foo/lib/python3.5/site-packages/click-6.4-py3.5.egg/click/core.py", line 1349, in process_value
    return self.type_cast_value(ctx, value)
  File "/home/david/projects/structureshrink/foo/lib/python3.5/site-packages/click-6.4-py3.5.egg/click/core.py", line 1338, in type_cast_value
    return _convert(value, (self.nargs != 1) + bool(self.multiple))
  File "/home/david/projects/structureshrink/foo/lib/python3.5/site-packages/click-6.4-py3.5.egg/click/core.py", line 1336, in _convert
    return self.type(value, self, ctx)
  File "/home/david/projects/structureshrink/foo/lib/python3.5/site-packages/click-6.4-py3.5.egg/click/types.py", line 38, in __call__
    return self.convert(value, param, ctx)
  File "/home/david/projects/structureshrink/foo/lib/python3.5/site-packages/click-6.4-py3.5.egg/click/types.py", line 426, in convert
    if not self.dir_okay and stat.S_ISDIR(st.st_mode):

I am running Python 3.5.1 and using click version 6.4.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions