Skip to content

Commit

Permalink
unify casing and spacing in docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
semiversus committed Sep 17, 2018
1 parent b473021 commit abab84a
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 64 deletions.
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ Synopsis
- Compact library (~1000 lines of code) and well documented
- Unit tested with pytest_, coding style checked with flake8_, static type checked with mypy_, static code checked with pylint_
- Operators known from ReactiveX_ and other streaming frameworks (like map_, combine_latest_, ...)
- Supporting ``asyncio`` for time depended operations and using coroutines (e.g. map_async_, debounce_, ...)
- Publishers are *awaitable* (e.g. ``await adc_raw``)
- Broker functionality via Hub_

+ Centralised object to keep track of publishers and subscribers
Expand All @@ -62,7 +60,8 @@ Showcase
========

In other frameworks Publisher_ are sometimes called ``Oberservable``. A subscriber
is able to observe changes the publisher is emitting.
is able to observe changes the publisher is emitting. With this basics you're
able to use the observer pattern - let's see!

Observer pattern
----------------
Expand Down
2 changes: 1 addition & 1 deletion broqer/default_error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def _default_error_callback(exc_type, exc_value, exc_traceback):
""" default error callback is printing traceback of the exception
""" Default error callback is printing traceback of the exception
"""
traceback.print_exception(exc_type, exc_value, exc_traceback)

Expand Down
8 changes: 4 additions & 4 deletions broqer/disposable.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def dispose(self) -> None:
""" .dispose() method has to be overwritten"""

def __enter__(self):
""" called on entry of a new context """
""" Called on entry of a new context """
return self

def __exit__(self, _type, _value, _traceback):
""" called on exit of the context. .dispose() is called here """
""" Called on exit of the context. .dispose() is called here """
self.dispose()


Expand All @@ -51,10 +51,10 @@ def dispose(self) -> None:

@property
def publisher(self) -> 'Publisher':
""" subscripted publisher """
""" Subscripted publisher """
return self._publisher

@property
def subscriber(self) -> 'Subscriber':
""" subscriber used in this subscription """
""" Subscriber used in this subscription """
return self._subscriber
20 changes: 10 additions & 10 deletions broqer/hub/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def emit(self, value: Any,
return self._subject.emit(value, who=self)

def assign(self, subject):
""" assigns the given subject to the topic """
""" Assigns the given subject to the topic """
assert isinstance(subject, (Publisher, Subscriber))

if self._subject is not None:
Expand All @@ -178,35 +178,35 @@ def assign(self, subject):
self.assignment_future.set_result(None)

def freeze(self):
""" called by hub when hub is going to be frozen """
""" Called by hub when hub is going to be frozen """
if self._subject is None:
raise ValueError('Topic %r is not assigned' % self._path)

@property
def assigned(self) -> bool:
""" telling as boolean if topic is assigned with a publisher/subscriber
""" Telling as boolean if topic is assigned with a publisher/subscriber
"""
return self._subject is not None

@property
def subject(self):
""" the assigned subject """
""" The assigned subject """
return self._subject

async def wait_for_assignment(self):
""" coroutine to wait until the assignment is finished """
""" Coroutine to wait until the assignment is finished """
if not self.assigned:
self.assignment_future = asyncio.get_event_loop().create_future()
await self.assignment_future

@property
def path(self) -> str:
""" topic path used as key in the hub """
""" Topic path used as key in the hub """
return self._path

@property
def hub(self) -> 'Hub':
""" reference to hub """
""" Reference to hub """
return self._hub


Expand All @@ -223,7 +223,7 @@ def assign(self, subject, meta=None): # pylint: disable=arguments-differ

@property
def meta(self):
""" the meta dictionary """
""" The meta dictionary """
return self._meta


Expand Down Expand Up @@ -265,13 +265,13 @@ def freeze(self, freeze: bool = True):

@property
def topics(self):
""" ordered dictionary with path:topic ordered by path """
""" Ordered dictionary with path:topic ordered by path """
topics_sorted = sorted(self._topics.items(), key=lambda t: t[0])
return MappingProxyType(OrderedDict(topics_sorted))

@property
def topic_factory(self):
""" used topic_factory """
""" Used topic_factory """
return self._topic_factory


Expand Down
4 changes: 2 additions & 2 deletions broqer/op/all_.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Applying any or all build in function to multiple publishers"""
""" Applying any or all build in function to multiple publishers"""
from typing import Callable
from typing import Any as Any_

Expand All @@ -9,7 +9,7 @@


class All(_MultiPredicate):
"""Applying any built in to source publishers"""
""" Applying any built in to source publishers"""
def __init__(self, *publishers: Publisher,
predicate: Callable[[Any_], bool] = None) -> None:
_MultiPredicate.__init__(self, *publishers, predicate=predicate)
Expand Down
4 changes: 2 additions & 2 deletions broqer/op/any_.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Applying any or all build in function to multiple publishers"""
""" Applying any or all build in function to multiple publishers"""
import asyncio
from typing import Dict, MutableSequence, Callable # noqa: F401
from typing import Any as Any_
Expand Down Expand Up @@ -55,7 +55,7 @@ def emit(self, value: Any_, who: Publisher) -> asyncio.Future:


class Any(_MultiPredicate):
"""Applying any built in to source publishers"""
""" Applying any built in to source publishers"""
def __init__(self, *publishers: Publisher,
predicate: Callable[[Any_], bool] = None) -> None:
_MultiPredicate.__init__(self, *publishers, predicate=predicate)
Expand Down
2 changes: 1 addition & 1 deletion broqer/op/map_.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Map(Operator):
"""
def __init__(self, publisher: Publisher, map_func: Callable[[Any], Any],
*args, unpack=False, **kwargs) -> None:
""" special care for return values:
""" Special care for return values:
* return `None` (or nothing) if you don't want to return a result
* return `None, ` if you want to return `None`
* return `(a, b), ` to return a tuple as value
Expand Down
4 changes: 2 additions & 2 deletions broqer/op/map_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def emit(self, value: Any, who: Publisher) -> None:
self._run_coro(value)

def _future_done(self, future):
""" will be called when the coroutine is done """
""" Will be called when the coroutine is done """
try:
# notify the subscribers (except result is an exception or NONE)
result = future.result() # may raise exception
Expand All @@ -202,7 +202,7 @@ def _future_done(self, future):
self._run_coro(value)

def _run_coro(self, value):
""" start the coroutine as task """
""" Start the coroutine as task """

# when LAST_DISTINCT is used only start coroutine when value changed
if self._options.mode is MODE.LAST_DISTINCT and \
Expand Down
8 changes: 4 additions & 4 deletions broqer/op/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def unsubscribe(self, subscriber: Subscriber) -> None:

@property
def source_publishers(self):
""" tuple with all source publishers """
""" Tuple with all source publishers """
return (self._publisher, )

@abstractmethod
def get(self): # pylint: disable=useless-return, no-self-use
""" get value of operator """
""" Get value of operator """


class MultiOperator(Publisher, Subscriber): # pylint: disable=abstract-method
Expand Down Expand Up @@ -82,12 +82,12 @@ def unsubscribe(self, subscriber: Subscriber) -> None:

@property
def source_publishers(self):
""" tuple with all source publishers """
""" Tuple with all source publishers """
return self._publishers

@abstractmethod
def get(self): # pylint: disable=useless-return, no-self-use
""" get value of operator """
""" Get value of operator """


def build_operator(operator_cls):
Expand Down
2 changes: 1 addition & 1 deletion broqer/op/operator_overloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def emit(self, value: Any, who: Publisher) -> asyncio.Future:


def apply_operator_overloading():
""" function to apply operator overloading to Publisher class """
""" Function to apply operator overloading to Publisher class """
for method in ('__lt__', '__le__', '__eq__', '__ne__', '__ge__', '__gt__',
'__add__', '__and__', '__lshift__', '__mod__', '__mul__',
'__pow__', '__rshift__', '__sub__', '__xor__', '__concat__',
Expand Down
2 changes: 1 addition & 1 deletion broqer/op/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get(self):
return Publisher.get(self) # raises ValueError

def _periodic_callback(self):
""" will be started on first emit """
""" Will be started on first emit """
try:
self.notify(self._state) # emit to all subscribers
except Exception: # pylint: disable=broad-except
Expand Down
2 changes: 1 addition & 1 deletion broqer/op/sliding_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def emit(self, value: Any, who: Publisher) -> asyncio.Future:
return None

def flush(self):
""" flush the queue - this will emit the current queue """
""" Flush the queue - this will emit the current queue """
if not self._emit_partial and len(self._state) != self._state.maxlen:
self.notify(tuple(self._state))
self._state.clear()
Expand Down
2 changes: 1 addition & 1 deletion broqer/op/throttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _wait_done_cb(self):
self._call_later_handler = None

def reset(self):
""" reseting duration for throttling """
""" Reseting duration for throttling """
if self._call_later_handler is not None:
self._call_later_handler.cancel()
self._call_later_handler = None
Expand Down
4 changes: 2 additions & 2 deletions broqer/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def unsubscribe(self, subscriber: 'Subscriber') -> None:
raise SubscriptionError('Subscriber is not registered')

def get(self): # pylint: disable=no-self-use
"""Return the value of the publisher. This is only working for stateful
""" Return the value of the publisher. This is only working for stateful
publishers. If publisher is stateless it will raise a ValueError.
:raises ValueError: when the publisher is stateless.
Expand All @@ -104,7 +104,7 @@ def notify(self, value: Any) -> asyncio.Future:

@property
def subscriptions(self):
""" property returning a tuple with all current subscribers """
""" Property returning a tuple with all current subscribers """
return tuple(self._subscriptions)

def __or__(self, apply: Callable[
Expand Down
2 changes: 1 addition & 1 deletion broqer/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Subscriber(metaclass=ABCMeta): # pylint: disable=too-few-public-methods
"""
@abstractmethod
def emit(self, value: Any, who: Publisher) -> asyncio.Future:
"""Send new value to the subscriber
""" Send new value to the subscriber
:param value: value to be send
:param who: reference to which publisher is emitting
"""
Expand Down
2 changes: 1 addition & 1 deletion broqer/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class NONE: # pylint: disable=too-few-public-methods
""" marker class used for initialization of undefined state """
""" Marker class used for initialization of undefined state """
pass
20 changes: 10 additions & 10 deletions broqer/utils/datatype_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def resolve_meta_key(hub, key, meta):
""" resolve a value when it's a string and starts with '>' """
""" Resolve a value when it's a string and starts with '>' """
if key not in meta:
return None
value = meta[key]
Expand All @@ -20,13 +20,13 @@ def resolve_meta_key(hub, key, meta):


class DT:
""" base class for a datatype """
""" Base class for a datatype """
def cast(self, topic, value): # pylint: disable=no-self-use,W0613
""" casting a string to the appropriate datatype """
""" Casting a string to the appropriate datatype """
return value

def check(self, topic, value): # pylint: disable=no-self-use,W0613
""" checking the value if it fits into the given specification """
""" Checking the value if it fits into the given specification """
pass


Expand Down Expand Up @@ -76,20 +76,20 @@ def __init__(self, hub: Hub, path: str) -> None:
MetaTopic.__init__(self, hub, path)

def cast(self, value):
"""Will cast value to the given datatype. It will not check the
""" Will cast value to the given datatype. It will not check the
value.
"""
return self._hub.topic_factory.cast(self, value)

def check(self, value):
"""Check the value against the datatype and limits defined in meta
""" Check the value against the datatype and limits defined in meta
dictionary. The value has to be in the appropriate datatype (may use
cast before)
"""
self._hub.topic_factory.check(self, value)

def checked_emit(self, value: Any) -> asyncio.Future:
""" casting and checking in one call """
""" Casting and checking in one call """

assert isinstance(self._subject, Subscriber), \
'Topic has to be a subscriber'
Expand All @@ -110,14 +110,14 @@ def __init__(self):
}

def add_datatype(self, name: str, datatype: DT):
""" register the datatype with it's name """
""" Register the datatype with it's name """
self._datatypes[name] = datatype

def __call__(self, hub: Hub, path: str) -> DTTopic:
return DTTopic(hub, path)

def cast(self, topic, value):
""" cast a string to the value based on the datatype """
""" Cast a string to the value based on the datatype """
datatype_key = topic.meta.get('datatype', 'none')
result = self._datatypes[datatype_key].cast(topic, value)
validate_dt = topic.meta.get('validate', None)
Expand All @@ -126,7 +126,7 @@ def cast(self, topic, value):
return result

def check(self, topic, value):
""" checking the value if it fits into the given specification """
""" Checking the value if it fits into the given specification """
datatype_key = topic.meta.get('datatype', 'none')
self._datatypes[datatype_key].check(topic, value)
validate_dt = topic.meta.get('validate', None)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""The setup script."""
""" The setup script."""

from setuptools import find_packages, setup

Expand Down

0 comments on commit abab84a

Please sign in to comment.