Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add None return types.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed May 24, 2023
1 parent 1f55c04 commit ee65d68
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions tests/util/caches/test_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DescriptorTestCase(unittest.TestCase):
@defer.inlineCallbacks
def test_cache(self):
class Cls:
def __init__(self):
def __init__(self) -> None:
self.mock = mock.Mock()

@descriptors.cached()
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_cache_num_args(self):
"""Only the first num_args arguments should matter to the cache"""

class Cls:
def __init__(self):
def __init__(self) -> None:
self.mock = mock.Mock()

@descriptors.cached(num_args=1)
Expand Down Expand Up @@ -126,7 +126,7 @@ class Cls:
def fn(self, arg1, arg2, arg3):
return self.mock(arg1, arg2, arg3)

def __init__(self):
def __init__(self) -> None:
self.mock = mock.Mock()

obj = Cls()
Expand Down Expand Up @@ -156,7 +156,7 @@ def test_cache_kwargs(self):
"""Test that keyword arguments are treated properly"""

class Cls:
def __init__(self):
def __init__(self) -> None:
self.mock = mock.Mock()

@descriptors.cached()
Expand Down Expand Up @@ -188,7 +188,7 @@ def fn(self, arg1, kwarg1=2):
self.assertEqual(r, "fish")
obj.mock.assert_not_called()

def test_cache_with_sync_exception(self):
def test_cache_with_sync_exception(self) -> None:
"""If the wrapped function throws synchronously, things should continue to work"""

class Cls:
Expand All @@ -209,7 +209,7 @@ def fn(self, arg1):
d = obj.fn(1)
self.failureResultOf(d, SynapseError)

def test_cache_with_async_exception(self):
def test_cache_with_async_exception(self) -> None:
"""The wrapped function returns a failure"""

class Cls:
Expand Down Expand Up @@ -349,7 +349,7 @@ def do_lookup():
@defer.inlineCallbacks
def test_cache_default_args(self):
class Cls:
def __init__(self):
def __init__(self) -> None:
self.mock = mock.Mock()

@descriptors.cached()
Expand Down Expand Up @@ -386,7 +386,7 @@ def fn(self, arg1, arg2=2, arg3=3):

def test_cache_iterable(self):
class Cls:
def __init__(self):
def __init__(self) -> None:
self.mock = mock.Mock()

@descriptors.cached(iterable=True)
Expand Down Expand Up @@ -417,7 +417,7 @@ def fn(self, arg1, arg2):
self.assertEqual(r.result, ["chips"])
obj.mock.assert_not_called()

def test_cache_iterable_with_sync_exception(self):
def test_cache_iterable_with_sync_exception(self) -> None:
"""If the wrapped function throws synchronously, things should continue to work"""

class Cls:
Expand All @@ -438,7 +438,7 @@ def fn(self, arg1):
d = obj.fn(1)
self.failureResultOf(d, SynapseError)

def test_invalidate_cascade(self):
def test_invalidate_cascade(self) -> None:
"""Invalidations should cascade up through cache contexts"""

class Cls:
Expand All @@ -463,7 +463,7 @@ async def func3(self, key, cache_context):
obj.invalidate()
top_invalidate.assert_called_once()

def test_cancel(self):
def test_cancel(self) -> None:
"""Test that cancelling a lookup does not cancel other lookups"""
complete_lookup: "Deferred[None]" = Deferred()

Expand All @@ -488,7 +488,7 @@ async def fn(self, arg1):
self.failureResultOf(d1, CancelledError)
self.assertEqual(d2.result, "123")

def test_cancel_logcontexts(self):
def test_cancel_logcontexts(self) -> None:
"""Test that cancellation does not break logcontexts.
* The `CancelledError` must be raised with the correct logcontext.
Expand All @@ -508,7 +508,7 @@ async def fn(self, arg1):

obj = Cls()

async def do_lookup():
async def do_lookup() -> None:
with LoggingContext("c1") as c1:
try:
await obj.fn(123)
Expand Down Expand Up @@ -765,7 +765,7 @@ class CachedListDescriptorTestCase(unittest.TestCase):
@defer.inlineCallbacks
def test_cache(self):
class Cls:
def __init__(self):
def __init__(self) -> None:
self.mock = mock.Mock()

@descriptors.cached()
Expand Down Expand Up @@ -828,7 +828,7 @@ def test_concurrent_lookups(self):
"""All concurrent lookups should get the same result"""

class Cls:
def __init__(self):
def __init__(self) -> None:
self.mock = mock.Mock()

@descriptors.cached()
Expand Down Expand Up @@ -871,7 +871,7 @@ def test_invalidate(self):
"""Make sure that invalidation callbacks are called."""

class Cls:
def __init__(self):
def __init__(self) -> None:
self.mock = mock.Mock()

@descriptors.cached()
Expand Down Expand Up @@ -960,7 +960,7 @@ async def list_fn(self, args):

obj = Cls()

async def do_lookup():
async def do_lookup() -> None:
with LoggingContext("c1") as c1:
try:
await obj.list_fn([123])
Expand All @@ -983,7 +983,7 @@ async def do_lookup():
)
self.assertEqual(current_context(), SENTINEL_CONTEXT)

def test_num_args_mismatch(self):
def test_num_args_mismatch(self) -> None:
"""
Make sure someone does not accidentally use @cachedList on a method with
a mismatch in the number args to the underlying single cache method.
Expand Down

0 comments on commit ee65d68

Please sign in to comment.