Skip to content

Commit

Permalink
Fixed #1 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jikuja authored Oct 10, 2022
1 parent 4e3c1f4 commit abcb86e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
19 changes: 6 additions & 13 deletions asyncio_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,23 @@ def exception_types(self) -> t.List[t.Type[Exception]]:
class GatheredResults:

# __dict__ is required for cached_property
__slots__ = ("results", "__dict__")
__slots__ = ("__results", "__dict__")

def __init__(self, results: t.List[t.Any]):
self.results = results
self.__results = results

###########################################################################

def __setattr__(self, key, value):
"""
Since we use cached_properties for most of the lookups, we don't want
the underlying results to be changed. There should be no reason for a
user to want to change the results, but just to be sure we raise a
ValueError.
"""
if key == "results":
raise ValueError("results is immutable")
super().__setattr__(key, value)
@property
def results(self):
return self.__results

@property
def all(self) -> t.List[t.Any]:
"""
Just a proxy.
"""
return self.results
return self.__results

###########################################################################

Expand Down
9 changes: 8 additions & 1 deletion tests/test_gathered_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,12 @@ def test_compound_exception(self):

def test_set(self):
results = GatheredResults([])
with self.assertRaises(ValueError):
with self.assertRaises(AttributeError):
results.results = None

def test_set_2(self):
results = asyncio.run(gather(good(), bad()))
with self.assertRaises(AttributeError):
results.results = None
self.assertEqual(len(results.all), 2)
self.assertEqual(len(results.results), 2)

0 comments on commit abcb86e

Please sign in to comment.