Skip to content
Snippets Groups Projects

Allow setting dictionary items in MagicDict by setting attributes

Merged Erwan Rouchet requested to merge setattr into master

Requires !124 (merged), closes #81 (closed)

A slightly annoying issue when writing tests for workers that should handle both Element and CachedElement: setting an attribute on a MagicDict does not set its item.

>>> e = Element()
>>> e.id = ''
>>> e["id"]
KeyError: 'id'

Since CachedElement does not have key-based access (e["id"]), if they set attributes on an Element, they might not be visible as dictionary keys. This changes the MagicDict behavior to just always set dictionary keys; the MagicDict's __getattr__ can retrieve those keys anyway, so it works transparently.

Edited by Erwan Rouchet

Merge request reports

Checking pipeline status.

Merged by Bastien AbadieBastien Abadie 3 years ago (Aug 23, 2021 9:08pm UTC)

Loading

Pipeline #78745 passed

Pipeline passed for fc9874df on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading