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

Make schema dict immutable #19

Merged
merged 21 commits into from
Feb 12, 2021
Merged

Make schema dict immutable #19

merged 21 commits into from
Feb 12, 2021

Conversation

janssenhenning
Copy link
Contributor

@janssenhenning janssenhenning commented Feb 9, 2021

Also see #16

This pull request adds the following things:

  • subclasses of UserList and UserDict, which prevent modifications to themselves after freeze has been called on the object
  • InputSchemaDict and OutputSchemaDict classes which initialize a frozen LockableDict from schemafiles
  • These contain xmlschemas for validation and the content previously in the schema_dict.py files
  • Also helper functions are referenced (for now only get_tag_xpath, get_attrib_xpath and get_tag_info)
  • Initialization possible with version string (fromVersion) and explicit filepaths (fromPath)
  • These classes contain a cache for storing references to already available Schema dictionaries (only for version initialization)
  • If you want to do something with the entries in the schema dicts you can get a mutable copy by calling get_unlocked() on the object (either the whole schema dict or the specific part you want to modify)

This made the following functions unnecessary and they are removed: update_schema_dicts, load_inpschema, load_outschema

- Introduced LockableDict, LockableList, which can prevent modifications to themselves
- New SchemaDict class subclass of LockableDict which is locked in __init__ and also includes some helper methods from schema_dict_util
…n LockableDict/List. Not optimal maybe I have to think about the inheritance structure again
…y builtin types are converted into lockable types

This means that e.g. any subclass of UserDict will still be mutable if it does not subclass LockableDict
I think this is a good compromise. Otherwise Functionality is lost silently
…che) and initialization from concrete file paths

Adapted parametrized tests for new classes with data_regression
create_inpschema_dict and create_outschema_dict now expect the complete filepath to the schema file
@janssenhenning janssenhenning added enhancement New feature or request parser/fleur Issues related to the file parsers for fleur labels Feb 9, 2021
LockableList needs to be converted manually after __init__ to propagate locking to sublists/dicts
@codecov-io
Copy link

codecov-io commented Feb 11, 2021

Codecov Report

Merging #19 (6cdc847) into develop (c0c81c4) will increase coverage by 0.44%.
The diff coverage is 95.88%.

@@             Coverage Diff             @@
##           develop      #19      +/-   ##
===========================================
+ Coverage    71.37%   71.82%   +0.44%     
===========================================
  Files           71       60      -11     
  Lines         9196     9305     +109     
===========================================
+ Hits          6564     6683     +119     
+ Misses        2632     2622      -10     

@janssenhenning janssenhenning merged commit 55c595d into develop Feb 12, 2021
@janssenhenning janssenhenning deleted the schema_dict_object branch February 12, 2021 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request parser/fleur Issues related to the file parsers for fleur
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants