Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State using ABC base class #90

Merged
merged 4 commits into from
Nov 11, 2021
Merged

State using ABC base class #90

merged 4 commits into from
Nov 11, 2021

Conversation

da-h
Copy link
Owner

@da-h da-h commented Nov 11, 2021

Implemented State using ABC base class

This MR adapts the implementation of state to use python's ABC base classes instead of extending dict.
This change allows to iterate over the variables in a module.

print("This module uses", len(state), "variables.")
for key in state:
    print("This module is using the variable", key)

Description

Some dict-operations could not be used on state variables (see #71).
This MR solves this by letting collections.abc.MutableMapping check if any functions are missing for a complete dict-implementation.

Things done in this MR

  • derived state class from MutableMapping
  • removed base class from temporary_state as it has never been used
  • added unit tests to check for modules local dict-operations, like iter(state) and len(state).

Check all before creating this PR:

  • Documentation adapted
  • unit tests adapted / created

@da-h da-h merged commit b90b82e into master Nov 11, 2021
@da-h da-h linked an issue Nov 11, 2021 that may be closed by this pull request
@da-h da-h deleted the dict_abc branch November 11, 2021 16:52
assert len(state.all) == 4, "Found global Variables %i" % len(state.all)

# Check if local state iterator has all variables that we expect
assert len(state) == 1, "Found lokal Variables %i" % len(state)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo lokal -> local

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx. Fix added to next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent behaviour of state.get()
2 participants