robhagemans / pcbasic

PC-BASIC - A free, cross-platform emulator for the GW-BASIC family of interpreters
http://www.pc-basic.org
Other
393 stars 48 forks source link

`from collections import Iterable` fails on Python 3.10 #171

Closed regeya closed 2 years ago

regeya commented 2 years ago

Hello, I'm partly writing to post my results here, and partly to ask what the best course of action is. :-) I'm an idiot when it comes to git, and if I'm fair that may be par for the course.

I'm running PC-BASIC on Fedora 35, which uses Python v3.10.1 To get the interpreter up and running, I needed to edit extensions.py and iostreams.py to import Iterable from collections.abc instead of collections i.e. 'from collections.abc import Iterable'. After that, it works perfectly.

I was considering making a comparison/contrast of a simple graphics demo on Tandy 1000 GW-BASIC vs PyGame and am stunned at how close PC-BASIC is to running GW-BASIC on a vintage PC. Thank you for your hard work.

robhagemans commented 2 years ago

Thanks for reporting! Looks like the abstract type Iterable has been moved to collections.abc at least in 3.5+ but apparently some of the 3.x versions are still downward compatible. Version 2.7 only has it in collections

I should be able to fairly easily resolve this - e.g. by moving the import into compat like other Python2/3 differences.

However, need to check why I'm using Iterable at all, below section from the Python docs suggests it may be better to use iter() instead.

class collections.abc.Iterable

ABC for classes that provide the iter() method.

Checking isinstance(obj, Iterable) detects classes that are registered as Iterable or that have an iter() method, but it does not detect classes that iterate with the getitem() method. The only reliable way to determine whether an object is iterable is to call iter(obj).

robhagemans commented 2 years ago

Fixed with commit bf97cb3c