Skip to content

Suggestion: config writer objects as python context managers #399

Closed
@rrei

Description

@rrei

This is just a suggestion for what I think would be a bit more pythonic implementation of the config writer objects that exist throughout gitpython. The basic pattern is:

  • get a config writer
  • set some values
  • call release() on the config writer object
cw = origin.config_writer
cw.set("pushurl", "other_url")
cw.release()

This pattern could be replaced with a context manager by providing the special methods __enter__() and __exit__() on the object returned by the config_writer property. The release() call would then occur automatically when the context is left.
The following example would be equivalent to the above:

with origin.config_writer as cw:
    cw.pushurl = "other_url"

This change could probably be done in a backwards-compatible manner, so everyone would be happy and this great library would become a tiny bit more pythonic :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions