Skip to content

Commit

Permalink
blacked
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnnsrs committed Oct 21, 2024
1 parent 6707ae0 commit 8bc2f4c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
2 changes: 0 additions & 2 deletions koil/composition/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def _repr_html_inline_(self):
return f"<table><tr><td>allow sync in async</td><td>{self.sync_in_async}</td></tr><tr><td>uvified</td><td>{self.uvify}</td></tr></table>"



@koilable(fieldname="koil", add_connectors=True, koil_class=PedanticKoil)
class KoiledModel(BaseModel):
koil: PedanticKoil = Field(default_factory=PedanticKoil, exclude=True)
Expand All @@ -48,7 +47,6 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
pass



class Composition(KoiledModel):
async def __aenter__(self: T) -> T:
for key, value in self:
Expand Down
1 change: 0 additions & 1 deletion koil/composition/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
class QtPedanticKoil(PedanticKoil, QtKoilMixin):
parent: Optional[QtWidgets.QWidget] = None
_qobject: Optional[QtCore.QObject] = None

37 changes: 13 additions & 24 deletions koil/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@
class UnconnectedSignalError(Exception):
pass


T = TypeVar("T")

class QtFuture(QtCore.QObject,Generic[T]):
""" A future that can be resolved in the Qt event loop

class QtFuture(QtCore.QObject, Generic[T]):
"""A future that can be resolved in the Qt event loop
Qt Futures are futures that can be resolved in the Qt event loop. They are
useful for functions that need to be resolved in the Qt event loop and are
not compatible with the asyncio event loop.
not compatible with the asyncio event loop.
QtFutures are generic and should be passed the type of the return value
when creating the future. This is useful for type hinting and for the
future to know what type of value to expect when it is resolved.
"""
cancelled: QtCore.Signal = QtCore.Signal()
"""

cancelled: QtCore.Signal = QtCore.Signal()

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -67,8 +67,6 @@ def _set_cancelled(self):
@property
def done(self):
return self.resolved or self.rejected or self.iscancelled



def resolve(self, *args: T):
if not args:
Expand All @@ -86,7 +84,7 @@ def reject(self, exp: Exception):
if self.aiofuture.done():
logger.warning(f"QtFuture {self} already done. Could not reject")
return

self.rejected = True

self.loop.call_soon_threadsafe(self.aiofuture.set_exception, exp)
Expand All @@ -96,9 +94,9 @@ class KoilStopIteration(Exception):
pass



T = TypeVar("T")


class QtGenerator(QtCore.QObject, Generic[T]):
"""A generator that can be run in the Qt event loop
Expand All @@ -111,6 +109,7 @@ class QtGenerator(QtCore.QObject, Generic[T]):
generator to know what type of value to expect when it is yielded.
"""

cancelled: QtCore.Signal = QtCore.Signal()

def __init__(self):
Expand All @@ -133,7 +132,6 @@ def throw(self, exception):
def stop(self):
self.loop.call_soon_threadsafe(self.aioqueue.put_nowait, KoilStopIteration())


def __aiter__(self):
return self

Expand Down Expand Up @@ -216,12 +214,7 @@ class QtYielder(QtCore.QObject, Generic[T, P]):
called = QtCore.Signal(QtGenerator, tuple, dict, object)
cancelled = QtCore.Signal(QtGenerator)

def __init__(
self,
coro: Callable[P, T],
use_context=True,
**kwargs
):
def __init__(self, coro: Callable[P, T], use_context=True, **kwargs):
super().__init__(**kwargs)
assert not inspect.isgeneratorfunction(
coro
Expand Down Expand Up @@ -262,7 +255,6 @@ async def aiterate(self, *args: P.args, timeout=None, **kwargs: P.kwargs):
raise



class QtListener:
def __init__(self, loop, queue) -> None:
self.queue = queue
Expand Down Expand Up @@ -581,16 +573,13 @@ def create_qt_koil(parent, auto_enter: bool = True) -> QtKoil:
return koil




class KoiledQtMixin(QtCore.QObject):


def __init__(self, parent=None):
super().__init__(parent)
self.koil = QtKoil(parent=self)
self.koil.enter()

def __del__(self):
self.koil.__exit__(None, None, None)
self.koil = None
self.koil = None
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "koil"
version = "1.0.0"
version = "1.0.1"
readme = "README.md"
description = "Async for a sync world"
authors = ["jhnnsrs <jhnnsrs@gmail.com>"]
Expand Down

0 comments on commit 8bc2f4c

Please sign in to comment.