title: How to enforce variable typing in Named Tuple in Python?
body: <p>I am following this <a href="http://alpopkes.com/posts/2018/08/coding-challenge-day-10-and-11/" rel="nofollow noreferrer">tutorial</a> on named tuple with specification of variable types. However, I modified the code (below), and even if I enter values of wrong types, there was no error message or programming break as a result. I understand you can write your own try/except to raise error exception, but is there a readily-available solution/syntax to enforce users entering the right type of variables. </p>
  
  <pre><code>from typing import NamedTuple
  
  class Pet(NamedTuple):
      pet_name: str
      pet_type: str
  
      def __repr__(self):
          return f"{self.pet_name}, {self.pet_type}"
  
  cleons_pet = Pet('Cotton', 'owl')
  print('cleons_pet: ', cleons_pet)
  
  cleons_pet_v2 = Pet(222, 1)
  print('cleons_pet_v2: ', cleons_pet_v2)
  
  # Output
  cleons_pet:  Cotton, owl
  cleons_pet_v2:  222, 1
  [Finished in 0.1s]
  </code></pre>