Skip to content

Conversation

@NuclearMissile
Copy link
Contributor

@NuclearMissile NuclearMissile commented Feb 22, 2024

The behavior of parallel() and Stream.parallel_of() not same.

Calling some actions on parallel stream created by parallel() like filter causes an AttributeError, but Stream.parallel_of() is OK. May because forget to set _parallelizer in StreamConverter.to_parallel_stream().

Error before fix after running test_parallel_stream.py:

Error
Traceback (most recent call last):
File "/Users//Desktop/projects/pystreamapi/tests/_parallel/test_parallel_stream.py", line 24, in test_parallel
.for_each(print))
^^^^^^^^^^^^^^^
File "/Users//Desktop/projects/pystreamapi/pystreamapi/_streams/__base_stream.py", line 36, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users//Desktop/projects/pystreamapi/pystreamapi/_streams/__base_stream.py", line 50, in wrapper
self._queue.execute_all()
File "/Users//Desktop/projects/pystreamapi/pystreamapi/_lazy/queue.py", line 22, in execute_all
proc.exec()
File "/Users//Desktop/projects/pystreamapi/pystreamapi/_lazy/process.py", line 20, in exec
self.__work(self.__arg)
File "/Users//Desktop/projects/pystreamapi/pystreamapi/_streams/__parallel_stream.py", line 29, in _filter
self._set_parallelizer_src()
File "/Users//Desktop/projects/pystreamapi/pystreamapi/_streams/__parallel_stream.py", line 90, in _set_parallelizer_src
self._parallelizer.set_source(self._source, self)
^^^^^^^^^^^^^^^^^^
AttributeError: 'ParallelNumericStream' object has no attribute '_parallelizer'

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Type: Bug fix

PR Summary: This pull request addresses an inconsistency between the behavior of parallel streams created via parallel() and Stream.parallel_of(). The issue was identified as an AttributeError occurring when terminal actions are called on parallel streams created by parallel(), which does not happen with streams created by Stream.parallel_of(). The proposed fix involves setting the _parallelizer attribute in the StreamConverter.to_parallel_stream() method to ensure uniform behavior across both methods of creating parallel streams.

Decision: Comment

📝 Type: 'Bug fix' - not supported yet.
  • Sourcery currently only approves 'Typo fix' PRs.
✅ Issue addressed: this change correctly addresses the issue or implements the desired feature.
No details provided.
✅ Small diff: the diff is small enough to approve with confidence.
No details provided.

General suggestions:

  • While the fix addresses the immediate AttributeError, it's important to consider the broader implications of directly modifying object attributes outside of their class definition. This can lead to issues with encapsulation and maintainability. A more robust solution might involve ensuring that all necessary attributes are set within the constructor or through dedicated methods, providing a clearer and more maintainable approach to object state management.
  • The addition of tests is commendable as it helps to ensure that the fix resolves the issue without introducing new ones. However, it would be beneficial to include tests that specifically target the scenario that was failing before the fix was applied, ensuring that the issue is fully resolved.
  • The pull request description provides a clear explanation of the problem and the proposed solution, which is helpful for reviewers. Including before and after examples is a good practice that could be enhanced by providing a brief explanation of how the images demonstrate the fix's effectiveness.

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@garlontas garlontas merged commit 8660a27 into pickwicksoft:main Feb 23, 2024
@garlontas
Copy link
Member

Thank you @NuclearMissile for contributing to pystreamapi!

@NuclearMissile NuclearMissile deleted the parallel_bug branch February 24, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants