geronimo-iia / async-rx

python async react library
https://geronimo-iia.github.io/async-rx/
Other
4 stars 0 forks source link

`Subject` errors if `on_next` method argument name is not item #6

Closed garyvdm closed 3 years ago

garyvdm commented 3 years ago

Subject calls on_next(item=item) which breaks if the argument name for your on_next method is not item. It would be nice to be able to call the argument anything, so that you can describe what it is, so that the code is more readable. This was not the case for a few other observables that I tested.

To Reproduce

async def on_next_number(number):
    print(number)

number_observer = rx_observer(on_next_number)

subject = rx_subject()
await subject.subscribe(number_observer)
await rx_range(start=0, stop=5).subscribe(subject)

Traceback (most recent call last):
  File "test.py", line 102, in main
    await rx_range(start=0, stop=5).subscribe(subject)
  File "ve/lib/python3.9/site-packages/async_rx/protocol/observable.py", line 37, in _subscribe
    return await subscribe(ensure_observable_contract_operator(an_observer))
  File "ve/lib/python3.9/site-packages/async_rx/observable/rx_range.py", line 22, in _subscribe
    await an_observer.on_next(item=i)
  File "ve/lib/python3.9/site-packages/async_rx/protocol/observable.py", line 66, in _on_next
    await an_observer.on_next(item)
  File "ve/lib/python3.9/site-packages/async_rx/protocol/observable.py", line 66, in _on_next
    await an_observer.on_next(item)
  File "ve/lib/python3.9/site-packages/async_rx/subject/rx_subject.py", line 83, in _on_next
    await o.on_next(item=item)
TypeError: on_next_number() got an unexpected keyword argument 'item'
geronimo-iia commented 3 years ago

Hello, yes I agree with you. It's due to NextHandler protocol definition. If we remove call like item=item in implementation, I think that test should pass. I will open this way on another branch of code.

geronimo-iia commented 3 years ago

I've released a new version 1.0.4, this one avoid calls with on_next(item=item) , let me known if i miss something

Jerome

garyvdm commented 3 years ago

Awesome. TYVM