Simplify things with a context manager.
ClosedPublic

Authored by ralph on Feb 25 2014, 2:32 PM.

Details

Summary

Previously, this code would raise the following exception if file it was trying
to read did not exist. The `datafile` variable would never be set.

File ".virtualenvs/taskotron/bin/runtask", line 9, in <module>
  load_entry_point('libtaskotron==0.0.3', 'console_scripts', 'runtask')()
File "devel/libtaskotron/libtaskotron/runner.py", line 131, in main
  task_data = taskyaml.parse_yaml_from_file(arg_data['taskfile'])
File "devel/libtaskotron/libtaskotron/taskyaml.py", line 9, in parse_yaml_from_file
  datafile.close()

UnboundLocalError: local variable 'datafile' referenced before assignment

Test Plan

Try to "runtask -e xchat-2.8.8-21.fc20 -a x86_64 task-rpmlint/rpmlint.yml"

Diff Detail

Branch
feature/fix-unboundlocalerror
Lint
No Linters Available
Unit
No Unit Test Coverage
jskladan accepted this revision.Feb 25 2014, 2:37 PM

/me likes!

kparal accepted this revision.Feb 25 2014, 2:38 PM

Looks good here!

ralph closed this revision.Feb 25 2014, 2:47 PM