Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9346103
D3177.id11287.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D3177.id11287.diff
View Options
diff --git a/requirements.txt b/requirements.txt
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,7 +3,7 @@
# dependency lines, see https://pip.readthedocs.org/en/1.1/requirements.html
vcversioner
attrs
-attrs_strict
+attrs_strict >= 0.0.7
hypothesis
python-dateutil
iso8601
diff --git a/swh/model/hypothesis_strategies.py b/swh/model/hypothesis_strategies.py
--- a/swh/model/hypothesis_strategies.py
+++ b/swh/model/hypothesis_strategies.py
@@ -18,12 +18,12 @@
from_regex,
integers,
just,
- lists,
none,
one_of,
sampled_from,
sets,
text,
+ tuples,
)
from .from_disk import DentryPerms
@@ -240,7 +240,7 @@
committer=persons_d(),
date=timestamps_with_timezone_d(),
committer_date=timestamps_with_timezone_d(),
- parents=lists(sha1_git()),
+ parents=tuples(sha1_git()),
directory=sha1_git(),
type=sampled_from([x.value for x in RevisionType]),
metadata=one_of(none(), revision_metadata()),
@@ -267,7 +267,7 @@
def directories_d():
- return builds(dict, entries=lists(directory_entries_d()))
+ return builds(dict, entries=tuples(directory_entries_d()))
def directories():
diff --git a/swh/model/model.py b/swh/model/model.py
--- a/swh/model/model.py
+++ b/swh/model/model.py
@@ -8,7 +8,7 @@
from abc import ABCMeta, abstractmethod
from enum import Enum
from hashlib import sha256
-from typing import Dict, List, Optional, TypeVar, Union
+from typing import Dict, Optional, Tuple, TypeVar, Union
import attr
from attrs_strict import type_validator
@@ -46,8 +46,8 @@
return value.value
elif isinstance(value, dict):
return {k: dictify(v) for k, v in value.items()}
- elif isinstance(value, list):
- return [dictify(v) for v in value]
+ elif isinstance(value, tuple):
+ return tuple(dictify(v) for v in value)
else:
return value
@@ -420,9 +420,7 @@
metadata = attr.ib(
type=Optional[Dict[str, object]], validator=type_validator(), default=None
)
- parents = attr.ib(
- type=List[Sha1Git], validator=type_validator(), default=attr.Factory(list)
- )
+ parents = attr.ib(type=Tuple[Sha1Git, ...], validator=type_validator(), default=())
id = attr.ib(type=Sha1Git, validator=type_validator(), default=b"")
@staticmethod
@@ -446,6 +444,7 @@
date=date,
committer_date=committer_date,
type=RevisionType(d.pop("type")),
+ parents=tuple(d.pop("parents")), # for BW compat
**d,
)
@@ -471,7 +470,7 @@
@attr.s(frozen=True)
class Directory(BaseModel, HashableObject):
- entries = attr.ib(type=List[DirectoryEntry], validator=type_validator())
+ entries = attr.ib(type=Tuple[DirectoryEntry, ...], validator=type_validator())
id = attr.ib(type=Sha1Git, validator=type_validator(), default=b"")
@staticmethod
@@ -482,7 +481,10 @@
def from_dict(cls, d):
d = d.copy()
return cls(
- entries=[DirectoryEntry.from_dict(entry) for entry in d.pop("entries")], **d
+ entries=tuple(
+ DirectoryEntry.from_dict(entry) for entry in d.pop("entries")
+ ),
+ **d,
)
diff --git a/swh/model/tests/test_hypothesis_strategies.py b/swh/model/tests/test_hypothesis_strategies.py
--- a/swh/model/tests/test_hypothesis_strategies.py
+++ b/swh/model/tests/test_hypothesis_strategies.py
@@ -66,7 +66,7 @@
for (key, value) in obj.items():
assert isinstance(key, (str, bytes)), key
assert_nested_dict(value)
- elif isinstance(obj, list):
+ elif isinstance(obj, tuple):
for value in obj:
assert_nested_dict(value)
elif isinstance(obj, (int, float, str, bytes, bool, type(None), datetime.datetime)):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jul 3, 3:44 PM (2 w, 12 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3216058
Attached To
D3177: Use Tuple instead of List in model declarations
Event Timeline
Log In to Comment