You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge pull request #153 from packit/context_management
Make context managers better
This commit introduces a new ContextManager decorator that builds on top of contextlib.contextmanager and effectively makes context managers a singleton. Any nested context of the same kind will be the same as the outermost context of that particular kind.
This makes it possible, for example, to set properties that internally use context managers inside an existing context, or in general mix and nest context managers almost freely.
There are still instances of conflicting context managers, for example macro_definitions() and sections(), that, when combined, will overwrite each other's underlying data. All such instances will be documented.
Now it is also possible to access data directly, avoiding the with statement, by using GeneratorContextManager.content property (I'm open to suggestions how to name it better):
for tag in spec.tags().content:
print(f"{tag.name}: {tag.expanded_value}")
No modifications will be preserved though.
RELEASE NOTES BEGIN
Context managers (Specfile.sections(), Specfile.tags() etc.) can now be nested and combined together (with one exception - Specfile.macro_definitions()), and it is also possible to use tag properties (e.g. Specfile.version, Specfile.license) inside them. It is also possible to access the data directly, avoiding the with statement, by using the content property (e.g. Specfile.tags().content), but be aware that no modifications done to such data will be preserved. You must use with to make changes.
RELEASE NOTES END
Reviewed-by: František Nečas <[email protected]>
Reviewed-by: Nikola Forró <None>
0 commit comments