From f1dd378ab14de6e006e48ac39e11c17f8a60c159 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Mon, 20 Mar 2023 18:31:11 -0400 Subject: [PATCH] chore: refactor (#34) * chore: refactor * fix(test): fix test semaphore on slow gh runners --- a_sync/__init__.py | 2 +- a_sync/aliases.py | 2 +- a_sync/modified.py | 2 +- a_sync/modifiers/__init__.py | 4 ++-- a_sync/modifiers/manager.py | 3 +-- a_sync/{ => modifiers}/semaphores.py | 0 a_sync/property.py | 2 +- tests/test_semaphore.py | 2 +- 8 files changed, 8 insertions(+), 9 deletions(-) rename a_sync/{ => modifiers}/semaphores.py (100%) diff --git a/a_sync/__init__.py b/a_sync/__init__.py index e4e2cc95..b49b96d7 100644 --- a/a_sync/__init__.py +++ b/a_sync/__init__.py @@ -2,7 +2,7 @@ from a_sync import aliases from a_sync.base import ASyncGenericBase from a_sync.decorator import a_sync -from a_sync.semaphores import (DummySemaphore, ThreadsafeSemaphore, +from a_sync.modifiers.semaphores import (DummySemaphore, ThreadsafeSemaphore, apply_semaphore) from a_sync.singleton import ASyncGenericSingleton diff --git a/a_sync/aliases.py b/a_sync/aliases.py index 2ad3886f..f3ef4b88 100644 --- a/a_sync/aliases.py +++ b/a_sync/aliases.py @@ -1,4 +1,4 @@ +from a_sync.modifiers.semaphores import dummy_semaphore as dummy from a_sync.property import a_sync_cached_property as cached_property from a_sync.property import a_sync_property as property -from a_sync.semaphores import dummy_semaphore as dummy diff --git a/a_sync/modified.py b/a_sync/modified.py index 38b1ee93..f372cc24 100644 --- a/a_sync/modified.py +++ b/a_sync/modified.py @@ -4,7 +4,7 @@ from a_sync import _helpers, _kwargs, exceptions from a_sync._typing import * -from a_sync.modifiers import ModifierManager +from a_sync.modifiers.manager import ModifierManager class Modified(Generic[T]): diff --git a/a_sync/modifiers/__init__.py b/a_sync/modifiers/__init__.py index e13762d6..e78ff7d3 100644 --- a/a_sync/modifiers/__init__.py +++ b/a_sync/modifiers/__init__.py @@ -1,8 +1,8 @@ from aiolimiter import AsyncLimiter from a_sync._typing import * -from a_sync.modifiers.manager import ModifierManager, valid_modifiers -from a_sync.semaphores import ThreadsafeSemaphore +from a_sync.modifiers.manager import valid_modifiers +from a_sync.modifiers.semaphores import ThreadsafeSemaphore def get_modifiers_from(thing: Union[dict, type, object]) -> ModifierKwargs: diff --git a/a_sync/modifiers/manager.py b/a_sync/modifiers/manager.py index 524135d7..f4dcffc2 100644 --- a/a_sync/modifiers/manager.py +++ b/a_sync/modifiers/manager.py @@ -1,10 +1,9 @@ import functools -from a_sync import semaphores from a_sync._typing import * from a_sync.config import user_set_default_modifiers, null_modifiers -from a_sync.modifiers import cache, limiter +from a_sync.modifiers import cache, limiter, semaphores valid_modifiers = [key for key in ModifierKwargs.__annotations__ if not key.startswith('_') and not key.endswith('_')] diff --git a/a_sync/semaphores.py b/a_sync/modifiers/semaphores.py similarity index 100% rename from a_sync/semaphores.py rename to a_sync/modifiers/semaphores.py diff --git a/a_sync/property.py b/a_sync/property.py index 72fb2853..f0d65874 100644 --- a/a_sync/property.py +++ b/a_sync/property.py @@ -6,7 +6,7 @@ from a_sync import config from a_sync._typing import * from a_sync.modified import Modified -from a_sync.modifiers import ModifierManager +from a_sync.modifiers.manager import ModifierManager class PropertyDescriptor(Modified[T]): diff --git a/tests/test_semaphore.py b/tests/test_semaphore.py index 8ee4779e..7161b218 100644 --- a/tests/test_semaphore.py +++ b/tests/test_semaphore.py @@ -38,4 +38,4 @@ async def test_semaphore_cached_property(i: int): # There is a 1 second sleep in this fn but a semaphore override with a value of 50. # You can tell it worked correctly because the class-defined semaphore value is just one, whch would cause this test to fail if it were used. # If the override is not working, all tests will complete in just over 1 second. - assert i == 1 or duration < 1.05 + assert i == 1 or duration < 1.4 # We increased the threshold from 1.05 to 1.4 to help tests pass on slow github runners