News for hackers. Stuff that matters.
Re:Show HN: Python-Type-Challenges, master Python typing wit... by crunchbang-excl on Wednesday November 29, 2023 @11:11AM (#38461221)
The challenge generic class can be solved without making any change to the pop() function.

I got it to work with this code:

# Code starts here

class Stack[T]: def __init__(self) -> None: self.items: list[T]

    def push(self, item: T) -> None:
        self.items.append(item)

    def pop(self):
        return self.items.pop()
# Code ends here

This code has fewer changes than the solution provided, and doesn't need imports. I'm not sure the solution needs those imports either.

Perhaps the tests for that challenge should cover more cases.

Re:Show HN: Python-Type-Challenges, master Python typing wit... by laike9m on Friday December 01, 2023 @01:51AM (#38483942)
Your solution is fine. Pyright can infer the return types, so you don't need to annotate the return type.

In fact this is describe in the solution https://github.com/laike9m/Python-Type-Challenges/blob/main/...