For me, adding --build to the compose command was not enough; I needed to first remove the build cache with the builder prune command. Only then were my changes to the Python files applied to the container. (Docker v28.4.0)
sudo docker builder prune
sudo docker compose up --build