Make all `.to_file()` methods into context managers

Open
#699 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Search the repository for all .to_file() methods and inspect their callers, starting with the usage in dwave-cloud-client linked from the issue and checking dwave-system compatibility. Determine which methods and call sites depend on the returned file remaining open; done means all affected methods use context managers and downstream integrations remain compatible.

Written by the indexing model from the issue text.

Description

enhancement question

I.e., change

class Model:
    def to_file(self, ...):
        file = tempfile.TemporaryFile(...)
        ...
        return file

to

class Model:
    @contextlib.contextmanager
    def to_file(self, ...):
        with tempfile.TemporaryFile(...) as file:
            ...
            yield file

I briefly tried to do this in https://github.com/dwavesystems/dwave-optimization/pull/697, but it has implications for the dwave-cloud-client and dwave-system so marking it for the future instead.

Dominant language
C++
Stars
32
Forks
38
Avg merge
1d 23h
Merged PRs (30d)
20

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dwavesystems/dwave-optimization

All issues in dwavesystems/dwave-optimization

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.