def cancel(self):
        """
        Seller can cancel a listing (end a listing early). Listing must be eligible to cancelled,
        depending on time left and if bids have been placed.
        """
        self.check_rule(
            ListingCanBeCancelled(
                time_left_in_listing=self.time_left_in_listing,
                no_bids_were_placed=len(self.bids) == 0,
            )
        )
        self.ends_at = datetime.utcnow()
        self.register_event(ListingWasCancelled(listing_id=self.id))

        Seller can cancel a listing (end a listing early). Listing must be eligible to cancelled,
        depending on time left and if bids have been placed.
        
src/modules/bidding/domain/entities.py