ietf-tools / xml2rfc

Generate RFCs and IETF drafts from document source in XML according to the IETF xml2rfc v2 and v3 vocabularies
https://ietf-tools.github.io/xml2rfc/
BSD 3-Clause "New" or "Revised" License
63 stars 35 forks source link

Refactor file handling code #1094

Open kesara opened 5 months ago

kesara commented 5 months ago

Off topic for the PR, but a couple of those might benefit from slight reorganization - instead of

  with open(...) as file:
    s = do_work()
    file.write(s)

you could refactor as

  s = do_work()
  with open(...) as file:
    file.write(s)

and that will have the benefit that a failure in do_work() won't leave a file around. That'd make sense if such a failure is more likely than a problem opening the file.

Actually, there's also pathlib.Path(...).write_text(...) or write_bytes(...) that will do the latter without the with noise.

Originally posted by @jennifer-richards in https://github.com/ietf-tools/xml2rfc/pull/1093#pullrequestreview-1856924199