<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def has_active_subscription(self, plan=None):
 		""" 		Checks to see if this customer has an active subscription to the given plan. 		:param plan: The plan for which to check for an active subscription. If plan is None and 			there exists only one active subscription, this method will check if that subscription 			is valid. Calling this method with no plan and multiple valid subscriptions for this customer will 			throw an exception. 		:type plan: Plan or string (plan ID) 		:returns: True if there exists an active subscription, False otherwise. 		:throws: TypeError if ``plan`` is None and more than one active subscription exists for this customer. 		"""


		if plan is None:
			valid_subscriptions = self._get_valid_subscriptions()

			if len(valid_subscriptions) == 0:
				return False
			elif len(valid_subscriptions) == 1:
				return True
			else:
				raise TypeError(
					"plan cannot be None if more than one valid subscription exists for this customer."
				)

		else:
			# Convert Plan to id
			if isinstance(plan, StripeModel):
				plan = plan.id

			return any(
				[
					subscription.is_valid()
					for subscription in self.subscriptions.filter(plan__id=plan)
				]
			)