Skip to content

Items refactoring#981

Merged
enkore merged 5 commits intoborgbackup:masterfrom
ThomasWaldmann:items-refactor
May 21, 2016
Merged

Items refactoring#981
enkore merged 5 commits intoborgbackup:masterfrom
ThomasWaldmann:items-refactor

Conversation

@ThomasWaldmann
Copy link
Member

@ThomasWaldmann ThomasWaldmann commented Apr 25, 2016

Item class + tests for now, WIP.

This is just the isolated item class + tests for now.
When this is merged, there needs to be a widespread refactoring to actually use this.

@codecov-io
Copy link

codecov-io commented Apr 25, 2016

Current coverage is 83.77%

Merging #981 into master will decrease coverage by 0.87%

  1. 8 files (not in diff) in borg were modified. more
    • Misses +31
    • Partials +11
    • Hits -182
  2. File borg/helpers.py was modified. more
    • Misses -1
    • Partials -2
    • Hits +9
  3. File ...org/platform_base.py (not in diff) was deleted. more
@@             master       #981   diff @@
==========================================
  Files            17         17          
  Lines          5153       5064    -89   
  Methods           0          0          
  Messages          0          0          
  Branches        919        908    -11   
==========================================
- Hits           4362       4242   -120   
- Misses          571        596    +25   
- Partials        220        226     +6   

Sunburst

Powered by Codecov. Last updated by b8303a3...ddb07ac

@ThomasWaldmann ThomasWaldmann added this to the 1.1 - near future goals milestone Apr 27, 2016
borg/item.py Outdated

def as_dict(self):
"""return the internal dictionary"""
return self._dict # XXX use StableDict?
Copy link
Contributor

@enkore enkore Apr 27, 2016

Choose a reason for hiding this comment

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

Since msgpack doesn't order keys (afaik)... yes, since hash-order in the item-stream would break metadata deduplication.

Would also avoid returning the mutable state of the object.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, before msgpack is invoked, existing code always wrapped the existing dict with StableDict().
So, putting this into .as_dict() ...

@enkore
Copy link
Contributor

enkore commented Apr 27, 2016

I think this should use __slots__ = ("_dict",); not for performance reasons, but to avoid setting invalid attributes that would silently fail to serialize via setattr and it's syntactic sugar:

>>> from borg.item import Item
>>> item = Item()
>>> item.some_invalid_key = 1234
>>> serialized = item.as_dict()
>>> serialized
{}

vs

>>> from borg.item import Item
>>> item = Item()
>>> item.some_invalid_key = 1234
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Item' object has no attribute 'some_invalid_key'

@ThomasWaldmann
Copy link
Member Author

ok, good idea.

@ThomasWaldmann
Copy link
Member Author

merge? this is isolated, so should be no problem.

@enkore enkore merged commit 1a02770 into borgbackup:master May 21, 2016
@enkore
Copy link
Contributor

enkore commented May 21, 2016

Just need to remember that we still have to do the actual refactoring :)

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.

3 participants