python-chess icon indicating copy to clipboard operation
python-chess copied to clipboard

Docstring could be more clear

Open Mark799 opened this issue 2 months ago • 1 comments

Docstring could be more clear on why this does not work:

board = chess.Board(None)
board.set_piece_at(0, chess.KNIGHT)

Mark799 avatar Oct 27 '25 22:10 Mark799

Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    board.set_piece_at(0, chess.KNIGHT)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python313\Lib\site-packages\chess\__init__.py", line 1816, in set_piece_at
    super().set_piece_at(square, piece, promoted=promoted)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python313\Lib\site-packages\chess\__init__.py", line 1090, in set_piece_at
    self._set_piece_at(square, piece.piece_type, piece.color, promoted)
                               ^^^^^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'piece_type'

Reason: You're feeding a PieceType chess.KNIGHT into a function that needs a Optional[Piece] which you can construct by using Piece(chess.KNIGHT, color)

Docstrings are purely not needed for this.

winapiadmin avatar Nov 02 '25 13:11 winapiadmin