Docstring could be more clear · Issue #1167 · niklasf/python-chess · GitHub
Skip to content

Docstring could be more clear #1167

Open

Description

@Mark799

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

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

Activity

  1. winapiadmin commented on Nov 2, 2025

    @winapiadmin
    Contributor
    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions