From 39f54825f86c1393ffd8c4dbeed10d69868c4de2 Mon Sep 17 00:00:00 2001 From: Lillian-Violet Date: Thu, 29 Feb 2024 21:38:28 +0100 Subject: [PATCH] Make all docstrings fully correct and have all data types hinted --- assignment.ipynb | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/assignment.ipynb b/assignment.ipynb index 7cccac1..92ccef4 100644 --- a/assignment.ipynb +++ b/assignment.ipynb @@ -2,9 +2,21 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'String' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m/home/lillian/Coding/jupyter/assignment.ipynb Cell 1\u001b[0m line \u001b[0;36m7\n\u001b[1;32m 69\u001b[0m \u001b[39mfor\u001b[39;00m cat \u001b[39min\u001b[39;00m cat_json:\n\u001b[1;32m 70\u001b[0m \u001b[39myield\u001b[39;00m Cat(\n\u001b[1;32m 71\u001b[0m cat\u001b[39m.\u001b[39mget(\u001b[39m\"\u001b[39m\u001b[39mid\u001b[39m\u001b[39m\"\u001b[39m),\n\u001b[1;32m 72\u001b[0m cat\u001b[39m.\u001b[39mget(\u001b[39m\"\u001b[39m\u001b[39murl\u001b[39m\u001b[39m\"\u001b[39m),\n\u001b[1;32m 73\u001b[0m cat\u001b[39m.\u001b[39mget(\u001b[39m\"\u001b[39m\u001b[39mwidth\u001b[39m\u001b[39m\"\u001b[39m),\n\u001b[1;32m 74\u001b[0m cat\u001b[39m.\u001b[39mget(\u001b[39m\"\u001b[39m\u001b[39mheight\u001b[39m\u001b[39m\"\u001b[39m),\n\u001b[1;32m 75\u001b[0m )\n\u001b[0;32m---> 78\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mget_cat_image\u001b[39m(url: String) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Image:\n\u001b[1;32m 79\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"Fetch an image url of the cat provided, returns an image file.\u001b[39;00m\n\u001b[1;32m 80\u001b[0m \n\u001b[1;32m 81\u001b[0m \u001b[39m Args:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 85\u001b[0m \u001b[39m Image: An image file parsed with the PIL library, read from a bytestream from the cats API.\u001b[39;00m\n\u001b[1;32m 86\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[1;32m 87\u001b[0m cr \u001b[39m=\u001b[39m requests\u001b[39m.\u001b[39mget(url)\n", + "\u001b[0;31mNameError\u001b[0m: name 'String' is not defined" + ] + } + ], "source": [ "from collections.abc import Generator\n", "from io import BytesIO\n", @@ -33,11 +45,11 @@ " return self.image.resize((self.width, self.height))\n", " return self.image\n", "\n", - " def save_image(self, path) -> bool:\n", + " def save_image(self, path: str) -> bool:\n", " \"\"\"Save image in cat to disk\n", "\n", " Args:\n", - " path (String): the path to save the cat picture to.\n", + " path (str): the path to save the cat picture to.\n", "\n", " Returns:\n", " bool: return if the function executed correctly, passthrough of the save function of Image.\n", @@ -45,7 +57,7 @@ " return self.get_image().save(f\"{path}/{self.id}.png\")\n", "\n", "\n", - "def get_cat_data(count=1) -> list[dict]:\n", + "def get_cat_data(count: int = 1) -> list[dict]:\n", " \"\"\"Fetch a cat from the cat API, return a parsed JSON object.\n", "\n", " Args:\n", @@ -60,15 +72,15 @@ " return response.json()\n", "\n", "\n", - "def get_cats(cat_json) -> Generator[Cat]:\n", + "def get_cats(cat_json: list[dict]) -> Generator[Cat]:\n", " \"\"\"Create a cat image from a JSON object formatted like the cat API\n", "\n", " Args:\n", " cat_json (list[dict]): Expects a list with a length > 1 with dicts in it that contains at least the fields:\n", - " (String) id\n", - " (String) url\n", - " (String) width\n", - " (String) height\n", + " (str) id\n", + " (str) url\n", + " (str) width\n", + " (str) height\n", "\n", " Returns:\n", " Generator[Cat]: A Generator object creating cat objects from the JSON object.\n", @@ -83,9 +95,12 @@ " )\n", "\n", "\n", - "def get_cat_image(url) -> Image:\n", + "def get_cat_image(url: str) -> Image:\n", " \"\"\"Fetch an image url of the cat provided, returns an image file.\n", "\n", + " Args:\n", + " url (str): the amount of cats to return.\n", + "\n", " Returns:\n", " Image: An image file parsed with the PIL library, read from a bytestream from the cats API.\n", " \"\"\"\n",