Skip to content

Cologler/use-context-python

Repository files navigation

use-context

GitHub Build Status PyPI

use some vars in current context and try rollback state when exit the context.

Usage

By default:

from use_context import use

ls = [1, 2, 3]
with use(ls):
    ls.append(5)
assert ls == [1, 2, 3]

For use ref (by name):

a = 15
with use(refs=['a']) as ctx:
    assert not ctx.is_ref_changed('a')
    a = 16
    assert a == 16
    assert ctx.is_ref_changed('a')
assert a == 15

👍

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages