Skip to content

Instantly share code, notes, and snippets.

@inesp
Created September 2, 2019 13:22
Show Gist options
  • Save inesp/14e20ecfdb2a223753995ea924d3293c to your computer and use it in GitHub Desktop.
Save inesp/14e20ecfdb2a223753995ea924d3293c to your computer and use it in GitHub Desktop.
class City:
# 1. add type hints, here we see that name shouldn't* be None
name: str = "vienna"
# 2. add more type hints
def create_zoo(self, owner: str) -> Optional[Zoo]:
zoo_configs: Dict[
str, ZooConfiguration
] = ZOOsConfigBuilder().get_configs()
config = zoo_configs.get(self.name)
# 3. we know that config is now either None
# or a ZooConfiguration instance. If it is
# a ZooConfiguration, then we call its property
# is_open_to_public, which must return a True/False.
if not config or not config.is_open_to_public:
# 4. here we are reminded, that the result
# of this function can be a None as well as
# a Zoo instance.
return None
# 5. here we know that config is a ZooConfiguration instance
# we know that it has a Callable variable called `get_config`
# and that this Callable accepts 2 parameters:
# - a string, zoo owner
# - an integer, zoo size
zoo_config: Dict[str, Any] = config.get_config(owner, 130)
return Zoo(zoo_config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment