Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python type checking dictionary mypy

from typing_extensions import TypedDict

class Person(TypedDict):
  name: str
  age: int
  address: str
    
class Employee:
  def __init__(self, name:str, age:int, address:str):
    self._name = name
    self._age = age
    self._address = address
  
  # Returns a dictionary 
  # {
  #   "name": "ABC",
  #   "age": 21,
  #   "address": "Some Street, State, AA"
  # }
  def employee_details(self) -> Person:
    return Person(name=self._name, age=self._age, address=self._address)
 
PREVIOUS NEXT
Tagged: #python #type #checking #dictionary #mypy
ADD COMMENT
Topic
Name
9+1 =