def _credit_card_type(self, card_type: Optional[CardType] = None) -> CreditCard:
        """Generate a random CreditCard instance of the specified card type."""
        if card_type is None:
            card_type = self.random_element(self.credit_card_types.keys())  # type: ignore[assignment]
        elif isinstance(card_type, CreditCard):
            return card_type
        return self.credit_card_types[card_type]  # type: ignore[index]
Generate a random CreditCard instance of the specified card type.
faker/providers/credit_card/__init__.py