Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit cd96d95

Browse files
authored
Sanitize set (#4945)
* ensure sets are sanitized to lists * update CHANGELOG
1 parent f0ae9f3 commit cd96d95

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Added `tokenizer_kwargs` and `transformer_kwargs` arguments to `PretrainedTransformerBackbone`
1313

14+
### Fixed
15+
16+
- `common.util.sanitize` now handles sets.
17+
18+
1419
## [v2.0.0](https://github.com/allenai/allennlp/releases/tag/v2.0.0) - 2021-01-27
1520

1621
### Added

allennlp/common/util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def sanitize(x: Any) -> Any:
9393
elif isinstance(x, (spacy.tokens.Token, Token)):
9494
# Tokens get sanitized to just their text.
9595
return x.text
96-
elif isinstance(x, (list, tuple)):
97-
# Lists and Tuples need their values sanitized
96+
elif isinstance(x, (list, tuple, set)):
97+
# Lists, tuples, and sets need their values sanitized
9898
return [sanitize(x_i) for x_i in x]
9999
elif x is None:
100100
return "None"

tests/common/util_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def test_sanitize(self):
5757

5858
assert util.sanitize(Sanitizable()) == {"sanitizable": True}
5959

60+
x = util.sanitize({1, 2, 3})
61+
assert isinstance(x, list)
62+
assert len(x) == 3
63+
6064
def test_import_submodules(self):
6165
(self.TEST_DIR / "mymodule").mkdir()
6266
(self.TEST_DIR / "mymodule" / "__init__.py").touch()

0 commit comments

Comments
 (0)