Skip to content

Instantly share code, notes, and snippets.

@driscollis
Created October 13, 2021 13:34
Show Gist options
  • Save driscollis/231c9418d5d9750562d8f06220a03038 to your computer and use it in GitHub Desktop.
Save driscollis/231c9418d5d9750562d8f06220a03038 to your computer and use it in GitHub Desktop.
Type hinting quiz
# vehicle.py
from collections import namedtuple
class Vehicle:
def __init__(self, name, veh_type):
self.name = name
self.veh_type = veh_type
self.add_ons = []
def add_on(self, name, color, placement):
AddOn = namedtuple("AddOn", "name color placement")
add_on = AddOn(name, color, placement)
self.add_ons.append(add_on)
return add_on
@driscollis
Copy link
Author

@evilensky You're close. I think you need a return type on the __init__ too (and you don't need Callable any more)

@driscollis
Copy link
Author

This looks pretty good. I don't think you need [AddOn], but it works for this example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment