libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
413 stars 36 forks source link

attribute error in python-tcod library #156

Closed propthink closed 4 months ago

propthink commented 4 months ago

Describe the bug I am following the 2020 version of the python-tcod roguelike tutorial located at this link: https://rogueliketutorials.com/tutorials/tcod/v2/

towards the end of chapter 7, I am getting an error when I try and run the render_names_at_mouse_location function

To Reproduce here is the code snippit from the tutorial that is causing the error:

def render_names_at_mouse_location( console: Console, x: int, y: int, engine: Engine ) -> None:

mouse_x, mouse_y = engine.mouse_location

names_at_mouse_location = get_names_at_location(
    x=mouse_x, y=mouse_y, game_map=engine.game_map
)
#console.print( x=x, y=y, string=names_at_mouse_location )
console.print(x=x, y=y, string=names_at_mouse_location)

specifically the last line is triggering the following error from the python-tcod lib, specifically on like 970 in the \tcod\console.py file:

"AttributeError: 'builtin_function_or_method' object has no attribute 'encode'"

Expected behavior the function should be printing a string at a given location

Screenshots error

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

HexDecimal commented 4 months ago

This error is expected. The string parameter requires a str type but names_at_mouse_location is a builtin_function_or_method as described by the error message.

For VSCode I'd recommend setting up the ms-python.mypy-type-checker plugin to detect these kinds of errors. Make sure get_names_at_location is returning the correct type.

Use Mypy to debug all cases of TypeError, AttributeError, and NameError.

propthink commented 4 months ago

Thank you for your advice, I will look into this issue. I apologize if this was an errant bug report

HexDecimal commented 4 months ago

It is errant, but I'm not bothered by it. The Discussions tab is a better place to ask for general help on the tutorial.