Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queue, Deque and Pair #39

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

Queue, Deque and Pair #39

wants to merge 17 commits into from

Conversation

TheHakerTech
Copy link
Member

@TheHakerTech TheHakerTech commented Jul 1, 2024

closes #35

Summary by Sourcery

This pull request introduces three new utility classes: UDeque, UQueue, and UPair, each designed to simplify common operations for double-ended queues, queues, and pairs respectively. Comprehensive documentation for each class has also been added.

  • New Features:
    • Introduced UDeque class to simplify working with double-ended queues, including methods for adding, removing, and accessing elements at both ends.
    • Introduced UQueue class to simplify working with queues, including methods for adding, removing, and accessing the head element.
    • Introduced UPair class to simplify working with pairs, including methods for accessing and setting the first and second elements.
  • Documentation:
    • Added documentation for UDeque in examples/udeque.md covering creation, element access, addition, deletion, and iteration.
    • Added documentation for UQueue in examples/uqueue.md covering creation, element access, addition, deletion, and iteration.
    • Added documentation for UPair in examples/upair.md covering creation, element access, setting values, and length calculation.

Copy link
Contributor

sourcery-ai bot commented Jul 1, 2024

Reviewer's Guide by Sourcery

This pull request introduces three new classes: UDeque, UQueue, and UPair, each with their respective methods for simplified operations. Comprehensive documentation and usage examples for each class are provided in new markdown files.

File-Level Changes

Files Changes
examples/udeque.md
ufpy/udeque.py
Introduced UDeque class and provided comprehensive documentation and usage examples.
examples/uqueue.md
ufpy/uqueue.py
Introduced UQueue class and provided comprehensive documentation and usage examples.
examples/upair.md
ufpy/upair.py
Introduced UPair class and provided comprehensive documentation and usage examples.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@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.

Hey @TheHakerTech - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Incorrect index used in setend method (link)
  • Incorrect reversed method implementation (link)
Here's what I looked at during the review
  • 🔴 General issues: 2 blocking issues, 8 other issues
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 13 issues found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

ufpy/udeque.py Outdated Show resolved Hide resolved
ufpy/udeque.py Outdated Show resolved Hide resolved
ufpy/udeque.py Outdated Show resolved Hide resolved
ufpy/udeque.py Outdated Show resolved Hide resolved
ufpy/udeque.py Outdated Show resolved Hide resolved
examples/udeque.md Outdated Show resolved Hide resolved
examples/udeque.md Outdated Show resolved Hide resolved
ufpy/udeque.py Outdated Show resolved Hide resolved
ufpy/udeque.py Outdated Show resolved Hide resolved
ufpy/udeque.py Outdated Show resolved Hide resolved
@bleudev
Copy link
Member

bleudev commented Jul 1, 2024

Because of stack, queue, pair and deque are from c++ stl, i want to move all this features in ustl package. Can you do this?

@bleudev bleudev changed the title UDeque UQueue, UDeque and UPair Jul 1, 2024
@bleudev
Copy link
Member

bleudev commented Jul 1, 2024

@sourcery-ai review

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Jul 1, 2024
Copy link
Contributor

@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.

Hey @TheHakerTech - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 10 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 7 issues found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

def __init__(self, *__list):
self.__list = list(__list)

def addend(self, value: VT) -> VT:
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Redundant check for self in addend method

The check if self: is redundant in the addend method. The method should always append the value to the list without checking if the deque is non-empty.

else:
raise IndexError("index out of range")

def addbegin(self, value: VT) -> VT:
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Redundant check for self in addbegin method

The check if self: is redundant in the addbegin method. The method should always insert the value at the beginning of the list without checking if the deque is non-empty.

ufpy/udeque.py Outdated
Comment on lines 75 to 80
def __getitem__(self, index: Any) -> VT:
if isinstance(index, int):
if index in (0, 1):
return self.__list[index]
else:
raise IndexError(f"{index} out of range (0, 1)")
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Incorrect index range check in getitem

The index range check in __getitem__ should allow for any valid index within the list, not just 0 and 1. This will cause an IndexError for valid indices beyond 1.

ufpy/udeque.py Outdated
if index in (0, 1):
return self.__list[index]
else:
raise IndexError(f"{index} out of range (0, 1)")
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Incorrect index range check in setitem

The index range check in __setitem__ should allow for any valid index within the list, not just 0 and 1. This will cause an IndexError for valid indices beyond 1.

ufpy/udeque.py Outdated
if index in (0, 1):
return self.__list[index]
else:
raise IndexError(f"{index} out of range (0, 1)")
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Incorrect index range check in delitem

The index range check in __delitem__ should allow for any valid index within the list, not just 0 and 1. This will cause an IndexError for valid indices beyond 1.

```

> [!NOTE]
> After using `for` your deque will be empty:
Copy link
Contributor

Choose a reason for hiding this comment

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

question (documentation): Question on UDeque Iteration Section

Is it necessary to mention that the deque will be empty after iteration? This behavior might be unexpected and should be highlighted more prominently if it is indeed the case.

```

> [!NOTE]
> After using `for` your queue will be empty:
Copy link
Contributor

Choose a reason for hiding this comment

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

question (documentation): Question on UQueue Iteration Section

Is it necessary to mention that the queue will be empty after iteration? This behavior might be unexpected and should be highlighted more prominently if it is indeed the case.

ufpy/udeque.py Outdated
Comment on lines 113 to 114
value = self.popbegin()
return value
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)

Suggested change
value = self.popbegin()
return value
return self.popbegin()

ufpy/upair.py Show resolved Hide resolved
ufpy/upair.py Show resolved Hide resolved
@bleudev bleudev dismissed sourcery-ai’s stale review July 1, 2024 17:57

He requested changes, which must be fixed

@bleudev bleudev changed the title UQueue, UDeque and UPair Queue, Deque and Pair Jul 1, 2024
@bleudev bleudev added this to the 0.3 milestone Jul 1, 2024
@bleudev bleudev marked this pull request as draft July 1, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UQueue, UDeque, UVector
2 participants