Skip to content

Commit

Permalink
Fixes for Python 3.9 (#78)
Browse files Browse the repository at this point in the history
* Update queue.py

* make PipelineException iterable

* pump version

* another exception instance

* blackify
  • Loading branch information
SimonBiggs authored Jan 5, 2022
1 parent 00b0e22 commit 94353ee
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
4 changes: 1 addition & 3 deletions pypeln/process/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
T = tp.TypeVar("T")


class PipelineException(tp.NamedTuple, BaseException):
exception: tp.Optional[tp.Type[BaseException]]
trace: str
PipelineException = pypeln_utils.PipelineException


class IterableQueue(Queue, tp.Generic[T], tp.Iterable[T]):
Expand Down
4 changes: 1 addition & 3 deletions pypeln/task/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
T = tp.TypeVar("T")


class PipelineException(tp.NamedTuple, BaseException):
exception: tp.Optional[tp.Type[BaseException]]
trace: str
PipelineException = pypeln_utils.PipelineException


class IterableQueue(asyncio.Queue, tp.Generic[T], tp.Iterable[T]):
Expand Down
6 changes: 1 addition & 5 deletions pypeln/thread/queue.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import sys
import time
import traceback
import typing as tp
from queue import Queue, Empty, Full
from threading import Lock

from pypeln import utils as pypeln_utils

Expand All @@ -12,9 +10,7 @@
T = tp.TypeVar("T")


class PipelineException(tp.NamedTuple, BaseException):
exception: tp.Optional[tp.Type[BaseException]]
trace: str
PipelineException = utils.pypeln_utils.PipelineException


class IterableQueue(Queue, tp.Generic[T], tp.Iterable[T]):
Expand Down
22 changes: 22 additions & 0 deletions pypeln/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import inspect
import sys
import typing as tp
import dataclasses

if sys.version_info >= (3, 8):
from typing import Protocol, runtime_checkable
Expand All @@ -17,6 +18,27 @@
B = tp.TypeVar("B")


@dataclasses.dataclass
class PipelineException(BaseException):
exception: tp.Optional[tp.Type[BaseException]]
trace: str

def __iter__(self):
self.n = 0
return self

def __next__(self):
# Workaround to make PipelineException act more like the
# namedtuple it was designed to be
try:
item = {0: self.exception, 1: self.trace}[self.n]
except KeyError as e:
raise StopIteration from e

self.n += 1
return item


class NoLock(Exception):
pass

Expand Down
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 = "pypeln"
version = "0.4.7"
version = "0.4.8"
description = ""
authors = ["Cristian Garcia <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 94353ee

Please sign in to comment.