psads / pythonds3

Data Structures package for Problem Solving with Algorithms and Data Structures using Python
GNU General Public License v3.0
35 stars 16 forks source link

TypeError while importing pythonds3 in python version 3.7.9 #11

Open sidharthism opened 1 year ago

sidharthism commented 1 year ago

Upon importing pythonds3, while learning stacks as part of the course pythonds3,

# Python 3.7.9 (tags/v3.7.9:13c94747c7)

import pythonds3

The following error occured:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./venv/lib/site-packages/pythonds3/__init__.py", line 9, in <module>
    from pythonds3.trees import (
  File "./venv/lib/site-packages/pythonds3/trees/__init__.py", line 7, in <module>
    from pythonds3.trees.binary_heap import BinaryHeap
  File "./venv/lib/site-packages/pythonds3/trees/binary_heap.py", line 13, in <module>
    class BinaryHeap:
  File "./venv/lib/site-packages/pythonds3/trees/binary_heap.py", line 52, in BinaryHeap
    def heapify(self, not_a_heap: list[Any], show_details: bool = False) -> None:
TypeError: 'type' object is not subscriptable
sidharthism commented 1 year ago

Most probably using primitive type list in trees/binary_heap.py", might be causing the issue.

 def heapify(self, not_a_heap: list[Any], show_details: bool = False) -> None:

[Update]

Tried using typing.List https://docs.python.org/3/library/typing.html?highlight=list#typing.List

from typing import Any, List
# ...
def heapify(self, not_a_heap: List[Any], show_details: bool = False) -> None:

Seem to fix the TypeError.

bnmnetp commented 1 year ago

There are no errors in 3.9 or 3.10 --- 3.7 is ancient!

I guess we should make this backward compatible or change the packaging to indicate that 3.9 is the minimum supported release.

Meanwhile -- version 3.0.3 will import successfully under older version of Python

sidharthism commented 1 year ago

Checked with the latest python versions. It's working fine. And thank you for the update! It seems that the issue is only with versions after 3 i.e. 3.7 till 3.8.5. Making it either backward compatible or changing the packaging to indicate that 3.9 is the minimum supported release will do I suppose.