Skip to content

Commit

Permalink
fixes for deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Günther Jena committed Sep 29, 2022
1 parent e217d95 commit 440e6a6
Show file tree
Hide file tree
Showing 23 changed files with 109 additions and 92 deletions.
2 changes: 1 addition & 1 deletion broqer/error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _default_error_callback(exc_type, exc_value, exc_traceback):
""" Default error callback is printing traceback of the exception
"""
exc_info = (exc_type, exc_value, exc_traceback)
log.warning('error handler for broqer catched exception', exc_info=exc_info)
log.warning('broqer catched exception', exc_info=exc_info)

raise exc_value.with_traceback(exc_traceback)

Expand Down
6 changes: 3 additions & 3 deletions broqer/op/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from typing import Any

from broqer import Publisher, NONE
from broqer.publisher import TValue
from broqer.publisher import ValueT
from broqer.operator import Operator


Expand All @@ -42,13 +42,13 @@ def __init__(self, init: Any = NONE) -> None:
Operator.__init__(self)
self._state = init

def get(self) -> TValue:
def get(self) -> ValueT:
if self._originator is None:
raise ValueError('Operator is missing originator')

return self._originator.get()

def emit(self, value: TValue, who: Publisher) -> None:
def emit(self, value: ValueT, who: Publisher) -> None:
if who is not self._originator:
raise ValueError('Emit from non assigned publisher')

Expand Down
8 changes: 4 additions & 4 deletions broqer/op/map_.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from typing import Any, Callable

from broqer import Publisher, NONE
from broqer.publisher import TValue
from broqer.publisher import ValueT
from broqer.operator import Operator


Expand All @@ -64,14 +64,14 @@ def __init__(self, function: Callable[[Any], Any], *args,
self._function = partial(function, *args, **kwargs)
self._unpack = unpack

def get(self) -> TValue:
def get(self) -> ValueT:
if self._subscriptions:
return self._state

if self._originator is None:
raise ValueError('Operator is missing originator')

value = self._originator.get() # type: TValue
value = self._originator.get() # type: ValueT

if value is NONE:
return value
Expand All @@ -82,7 +82,7 @@ def get(self) -> TValue:

return self._function(value)

def emit(self, value: TValue, who: Publisher) -> None:
def emit(self, value: ValueT, who: Publisher) -> None:
if who is not self._originator:
raise ValueError('Emit from non assigned publisher')

Expand Down
6 changes: 3 additions & 3 deletions broqer/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# pylint: disable=cyclic-import
from broqer import Publisher, SubscriptionDisposable, Subscriber
from broqer.publisher import TValue
from broqer.publisher import ValueT


class Operator(Publisher, Subscriber):
Expand Down Expand Up @@ -54,7 +54,7 @@ def unsubscribe(self, subscriber: Subscriber) -> None:
self._originator.unsubscribe(self)
Publisher.reset_state(self)

def notify(self, value: TValue) -> None:
def notify(self, value: ValueT) -> None:
raise ValueError('Operator doesn\'t support .notify()')

@abstractmethod
Expand Down Expand Up @@ -95,7 +95,7 @@ def unsubscribe(self, subscriber: Subscriber) -> None:
publisher.unsubscribe(self)
Publisher.reset_state(self)

def notify(self, value: TValue) -> None:
def notify(self, value: ValueT) -> None:
raise ValueError('Operator doesn\'t support .notify()')

def emit(self, value: typing.Any, who: Publisher) -> None:
Expand Down
2 changes: 1 addition & 1 deletion broqer/operator_overloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _op_unary(operand, operation=_method):
def _getattr(publisher, attribute_name):
if not publisher.inherited_type or \
not hasattr(publisher.inherited_type, attribute_name):
raise AttributeError('Attribute %r not found' % attribute_name)
raise AttributeError(f'Attribute {attribute_name!r} not found')
return _GetAttr(publisher, attribute_name)

setattr(Publisher, '__getattr__', _getattr)
13 changes: 6 additions & 7 deletions broqer/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class SubscriptionError(ValueError):
"""


TInherit = TypeVar('TInherit') # Type to inherited behavior from
TValue = TypeVar('TValue') # Type of publisher state and emitted value
ValueT = TypeVar('ValueT') # Type of publisher state and emitted value
SubscriptionCBT = Callable[[bool], None]


Expand Down Expand Up @@ -56,11 +55,11 @@ class Publisher:
indirectly) dependent on.
"""
@overload # noqa: F811
def __init__(self, *, type_: Type[TValue] = None):
def __init__(self, *, type_: Type[ValueT] = None):
pass

@overload # noqa: F811
def __init__(self, init: TValue, type_: Type[TValue] = None): # noqa: F811
def __init__(self, init: ValueT, type_: Type[ValueT] = None): # noqa: F811
pass

def __init__(self, init=NONE, type_=None): # noqa: F811
Expand All @@ -73,7 +72,7 @@ def __init__(self, init=NONE, type_=None): # noqa: F811
else:
self._inherited_type = None

self._subscriptions = list() # type: List[Subscriber]
self._subscriptions = [] # type: List[Subscriber]
self._on_subscription_cb = None # type: Optional[SubscriptionCBT]
self._dependencies = () # type: Tuple[Publisher, ...]

Expand Down Expand Up @@ -132,11 +131,11 @@ def unsubscribe(self, subscriber: 'Subscriber') -> None:

raise SubscriptionError('Subscriber is not registered')

def get(self) -> TValue:
def get(self) -> ValueT:
""" Return the state of the publisher. """
return self._state

def notify(self, value: TValue) -> None:
def notify(self, value: ValueT) -> None:
""" Calling .emit(value) on all subscribers and store state.
:param value: value to be emitted to subscribers
Expand Down
10 changes: 5 additions & 5 deletions broqer/publishers/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import asyncio
from typing import Callable, Type, Any, Optional

from broqer.publisher import Publisher, TValue, SubscriptionDisposable
from broqer.publisher import Publisher, ValueT, SubscriptionDisposable
from broqer.subscriber import Subscriber


Expand All @@ -15,7 +15,7 @@ class PollPublisher(Publisher):
:param interval: Time in seconds between polling calls
"""
def __init__(self, poll_cb: Callable[[], Any], interval: float, *,
type_: Type[TValue] = None):
type_: Type[ValueT] = None):
Publisher.__init__(self, type_=type_)
self.poll_cb = poll_cb
self.interval = interval
Expand All @@ -26,7 +26,7 @@ def subscribe(self, subscriber: Subscriber,
if not self._subscriptions:
# call poll_cb once to set internal state and schedule a _poll call
self._state = self.poll_cb()
loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
assert self._poll_handler is None, '_poll_handler already assigned'
self._poll_handler = loop.call_later(self.interval, self._poll)

Expand All @@ -46,9 +46,9 @@ def _poll(self):
value = self.poll_cb()
Publisher.notify(self, value)

loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
self._poll_handler = loop.call_later(self.interval, self._poll)

def notify(self, value: TValue) -> None:
def notify(self, value: ValueT) -> None:
""" PollPublisher does not support .notify calls """
raise ValueError(self.notify.__doc__)
10 changes: 5 additions & 5 deletions broqer/subscribers/on_emit_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
>>> from broqer import Value, op, OnEmitFuture
>>> s = Value()
>>> _ = asyncio.get_event_loop().call_later(0.05, s.emit, 1)
>>> _ = asyncio.get_running_loop().call_later(0.05, s.emit, 1)
>>> asyncio.get_event_loop().run_until_complete(OnEmitFuture(s) )
>>> asyncio.get_running_loop().run_until_complete(OnEmitFuture(s) )
1
#>>> _ = asyncio.get_event_loop().call_later(0.05, s.emit, (1, 2))
#>>> asyncio.get_event_loop().run_until_complete(s)
#>>> _ = asyncio.get_running_loop().call_later(0.05, s.emit, (1, 2))
#>>> asyncio.get_running_loop().run_until_complete(s)
(1, 2)
"""
import asyncio
Expand All @@ -36,7 +36,7 @@ class OnEmitFuture(broqer.Subscriber, asyncio.Future):
def __init__(self, publisher: 'Publisher', timeout=None,
omit_subscription=False, loop=None):
if loop is None:
loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()

asyncio.Future.__init__(self, loop=loop)
self.add_done_callback(self._cleanup)
Expand Down
2 changes: 1 addition & 1 deletion broqer/subscribers/sink_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
>>> _d = s.subscribe(SinkAsync(delay_add))
>>> s.emit(0)
>>> s.emit(1)
>>> asyncio.get_event_loop().run_until_complete(asyncio.sleep(0.02))
>>> asyncio.run(asyncio.sleep(0.02))
Starting with argument 0
Starting with argument 1
Finished with argument 0
Expand Down
5 changes: 3 additions & 2 deletions broqer/subscribers/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def _trace_handler(publisher: 'Publisher', value, label=None):
""" Default trace handler is printing the timestamp, the publisher name
and the emitted value
"""
line = '--- %8.3f: ' % (time() - Trace._timestamp_start)
time_diff = time() - Trace._timestamp_start
line = f'--- {time_diff:8.3f}: '
line += repr(publisher) if label is None else label
line += ' %r' % (value,)
line += f' {value!r}'
print(line)
2 changes: 1 addition & 1 deletion broqer/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, callback: Optional[Callable[[], None]] = None,
loop: Optional[asyncio.BaseEventLoop] = None):
self._callback = callback
self._handle = None # type: Optional[asyncio.Handle]
self._loop = loop or asyncio.get_event_loop()
self._loop = loop or asyncio.get_running_loop()
self._args = None

def start(self, timeout: float, args=()) -> None:
Expand Down
3 changes: 2 additions & 1 deletion broqer/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def emit(self, value: Any,


def dependent_subscribe(publisher: Publisher, value: Value):
""" Let `value` subscribe to `publisher` only when `value` itself is subscribed
""" Let `value` subscribe to `publisher` only when `value` itself is
subscribed
:param publisher: publisher to be subscribed, when value is subscribed
:param value: value, which will receive .emit calls from `publisher`
"""
Expand Down
2 changes: 1 addition & 1 deletion examples/await.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async def main():
print('Value: ', await value)
print('Number of subscribers: %d' % len(value.subscriptions))

loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()

loop.call_later(0.2, value.emit, 1)
loop.call_later(0.4, value.emit, 2)
Expand Down
2 changes: 1 addition & 1 deletion examples/from_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
| op.Sink(print)
)

loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
loop.run_until_complete(asyncio.sleep(10))
2 changes: 1 addition & 1 deletion examples/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ async def main():
adc_raw.emit(50)
await asyncio.sleep(2)

loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
loop.run_until_complete(main())
7 changes: 4 additions & 3 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pytest==3.7.4
pytest-asyncio==0.9.0
pytest-cov==2.5.1
pytest==7.1.3
pytest-asyncio==0.19.0
pytest-cov==4.0.0
tox==2.9.1
Sphinx==1.7.8
sphinx-rtd-theme==0.4.0
Expand All @@ -12,3 +12,4 @@ codecov==2.0.15
setuptools_scm==3.3.3
wheel==0.35.1
pylama==7.7.1
pylint==2.15.3
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ exclude_lines =
[tool:pytest]
testpaths = tests broqer README.rst
doctest_optionflags = ELLIPSIS
addopts = --cov-report=html --no-cov-on-fail -q --cov=broqer --doctest-modules
addopts = --cov-report=html --no-cov-on-fail -q --cov=broqer

[pylama]
async = 1
format = pycodestyle
paths = broqer
skip = broqer/_version.py
linters = pycodestyle,mccabe,pylint
linters = pycodestyle,mccabe,pylint

0 comments on commit 440e6a6

Please sign in to comment.