TStand90/tcod_tutorial_v2

Entities is initialized as a list, but code treats it as a set.

Dowsley opened this issue · 2 comments

dungeon = GameMap(map_width, map_height, entities=[player])

Python 3.10 will break with other parts of the code such as.

for entity in self.game_map.entities - {self.player}:
TypeError: unsupported operand type(s) for -: 'list' and 'set'

It seems to be a simple fix - just declare it as {player}. I didn't make a pull request because I don't know in which part this "mistake" began, or if there's something else I'm missing.

GameMap's initializer always converts that input into a set, this part is missing from your code:

class GameMap:
def __init__(self, width: int, height: int, entities: Iterable[Entity] = ()):
self.width, self.height = width, height
self.entities = set(entities)

Your change would be a little more efficient though. Some classes would probably be better written with attrs.

Thank you, I missed that default when following your guide.

I believe it's not worth a change given that.