Created
September 22, 2021 22:08
-
-
Save rednafi/80506e54a7a9540ee210d174d2a5e5fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "41c1852b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<bound method InteractiveShell.excepthook of <ipykernel.zmqshell.ZMQInteractiveShell object at 0x7fd356e1a0a0>>" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from rich.pretty import pprint as print\n", | |
"from rich.traceback import install \n", | |
"\n", | |
"install()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "b3553473", | |
"metadata": {}, | |
"source": [ | |
"### `super()` is mysterious; keep `__mro__` in mind and call w/o any arg" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "2881ddcd", | |
"metadata": {}, | |
"source": [ | |
"* Use `super()` without explicit class announcement. \n", | |
"* Inheritance is tricky, always check `__mro__` while subclassing as super can\n", | |
" break superclasses after subclassing.\n", | |
" " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "c924dc29", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"class Adam: \n", | |
" def talk(self):\n", | |
" print(\"Adam says hi!\")\n", | |
"\n", | |
"class Eve:\n", | |
" def talk(self):\n", | |
" print(\"Eve says hi!\")\n", | |
"\n", | |
"\n", | |
"class Dad(Adam, Eve):\n", | |
" def talk(self):\n", | |
" print(\"Dad says hi!\")\n", | |
"\n", | |
"\n", | |
"class Mom(Adam, Eve):\n", | |
" def talk(self):\n", | |
" print(\"Mom says hi!\")\n", | |
"\n", | |
"\n", | |
"class Kid1(Dad, Mom):\n", | |
" def talk(self):\n", | |
" super().talk()\n", | |
"\n", | |
"class Kid2(Dad, Mom):\n", | |
" def talk(self):\n", | |
" super(Dad, self).talk()\n", | |
" \n", | |
"class StepMom(Mom):\n", | |
" def talk(self):\n", | |
" super().talk()\n", | |
" \n", | |
"class SubKid1(Kid1, StepMom):\n", | |
" def talk(self):\n", | |
" super().talk()\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "490c563d", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">'Dad says hi!'</span>\n", | |
"</pre>\n" | |
], | |
"text/plain": [ | |
"\u001b[32m'Dad says hi!'\u001b[0m\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n", | |
"</pre>\n" | |
], | |
"text/plain": [ | |
"\u001b[3;35mNone\u001b[0m\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">'Mom says hi!'</span>\n", | |
"</pre>\n" | |
], | |
"text/plain": [ | |
"\u001b[32m'Mom says hi!'\u001b[0m\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n", | |
"</pre>\n" | |
], | |
"text/plain": [ | |
"\u001b[3;35mNone\u001b[0m\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"k1 = Kid1()\n", | |
"k2 = Kid2()\n", | |
"\n", | |
"\n", | |
"print(k1.talk())\n", | |
"print(k2.talk())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "a5b3ada9", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">(</span>\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.Kid1'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.Dad'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.Mom'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.Adam'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.Eve'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'object'</span><span style=\"font-weight: bold\">></span>\n", | |
"<span style=\"font-weight: bold\">)</span>\n", | |
"</pre>\n" | |
], | |
"text/plain": [ | |
"\u001b[1m(\u001b[0m\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.Kid1'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.Dad'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.Mom'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.Adam'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.Eve'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'object'\u001b[0m\u001b[1m>\u001b[0m\n", | |
"\u001b[1m)\u001b[0m\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"print(Kid1.__mro__)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"id": "21e09a6d", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">(</span>\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.SubKid1'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.Kid1'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.Dad'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.StepMom'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.Mom'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.Adam'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'__main__.Eve'</span><span style=\"font-weight: bold\">></span>,\n", | |
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">class</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #008000; text-decoration-color: #008000\">'object'</span><span style=\"font-weight: bold\">></span>\n", | |
"<span style=\"font-weight: bold\">)</span>\n", | |
"</pre>\n" | |
], | |
"text/plain": [ | |
"\u001b[1m(\u001b[0m\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.SubKid1'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.Kid1'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.Dad'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.StepMom'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.Mom'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.Adam'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'__main__.Eve'\u001b[0m\u001b[1m>\u001b[0m,\n", | |
"\u001b[2;32m│ \u001b[0m\u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'object'\u001b[0m\u001b[1m>\u001b[0m\n", | |
"\u001b[1m)\u001b[0m\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"print(SubKid1.__mro__)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "77bb3b84", | |
"metadata": {}, | |
"source": [ | |
"### Always use trailing comma" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "d4c3cd82", | |
"metadata": {}, | |
"source": [ | |
"* Trailing comma makes black work better. There's an extension that enforces that.\n", | |
"* Trailing comma creates smaller diff.\n", | |
"* Can we reduce the line lengtht to ~80-90? Ours is too long 120. It works great\n", | |
" with statically typed languags (That's why Torvalds like it 120) but in the \n", | |
" Python community, the standard is ~90 ish. " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "ee2e8275", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #ff0000; text-decoration-color: #ff0000\">╭──────────────────────────── </span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">Traceback </span><span style=\"color: #bf7f7f; text-decoration-color: #bf7f7f; font-weight: bold\">(most recent call last)</span><span style=\"color: #ff0000; text-decoration-color: #ff0000\"> ────────────────────────────╮</span>\n", | |
"<span style=\"color: #ff0000; text-decoration-color: #ff0000\">│</span> <span style=\"color: #bfbf7f; text-decoration-color: #bfbf7f\">/tmp/ipykernel_2679343/</span><span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">2890023608.py</span>:<span style=\"color: #0000ff; text-decoration-color: #0000ff\">2</span> in <span style=\"color: #00ff00; text-decoration-color: #00ff00\"><module></span> <span style=\"color: #ff0000; text-decoration-color: #ff0000\">│</span>\n", | |
"<span style=\"color: #ff0000; text-decoration-color: #ff0000\">│</span> <span style=\"color: #ff0000; text-decoration-color: #ff0000\">│</span>\n", | |
"<span style=\"color: #ff0000; text-decoration-color: #ff0000\">│</span> <span style=\"color: #800000; text-decoration-color: #800000; font-style: italic\">[Errno 2] No such file or directory: '/tmp/ipykernel_2679343/2890023608.py'</span> <span style=\"color: #ff0000; text-decoration-color: #ff0000\">│</span>\n", | |
"<span style=\"color: #ff0000; text-decoration-color: #ff0000\">╰───────────────────────────────────────────────────────────────────────────────────────────╯</span>\n", | |
"<span style=\"color: #ff0000; text-decoration-color: #ff0000; font-weight: bold\">NameError: </span>name <span style=\"color: #008000; text-decoration-color: #008000\">'orders_models'</span> is not defined\n", | |
"</pre>\n" | |
], | |
"text/plain": [ | |
"\u001b[91m╭─\u001b[0m\u001b[91m─────────────────────────── \u001b[0m\u001b[1;31mTraceback \u001b[0m\u001b[1;2;31m(most recent call last)\u001b[0m\u001b[91m ───────────────────────────\u001b[0m\u001b[91m─╮\u001b[0m\n", | |
"\u001b[91m│\u001b[0m \u001b[2;33m/tmp/ipykernel_2679343/\u001b[0m\u001b[1;33m2890023608.py\u001b[0m:\u001b[94m2\u001b[0m in \u001b[92m<module>\u001b[0m \u001b[91m│\u001b[0m\n", | |
"\u001b[91m│\u001b[0m \u001b[91m│\u001b[0m\n", | |
"\u001b[91m│\u001b[0m \u001b[3;31m[Errno 2] No such file or directory: '/tmp/ipykernel_2679343/2890023608.py'\u001b[0m \u001b[91m│\u001b[0m\n", | |
"\u001b[91m╰───────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n", | |
"\u001b[1;91mNameError: \u001b[0mname \u001b[32m'orders_models'\u001b[0m is not defined\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"## Bad.\n", | |
"orders_models.Counter.objects.update_or_create(name=\"Accession Number\", defaults={\"int_value\": 0})\n", | |
"\n", | |
"## Good.\n", | |
"orders_models.Counter.objects.update_or_create(\n", | |
" name=\"Accession Number\",\n", | |
" defaults={\"int_value\": 0},\n", | |
" )\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "d8dc538e", | |
"metadata": {}, | |
"source": [ | |
"### Use python 3.8+ syntax only" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "4911f349", | |
"metadata": {}, | |
"source": [ | |
"* Use f-strings instead of `.format()`. F-string is implemented in C, whereas `.format()` is a slower python method call.\n", | |
"\n", | |
"* Use multi-line single quote to break longer line.\n", | |
"\n", | |
"* Use `__future__` import in type hint.\n", | |
"\n", | |
"* Pick a consistent comment structure.\n", | |
"\n", | |
"* We can add [pyupgrade](https://github.com/asottile/pyupgrade) linter to our local makefile. " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "85f63bfc", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Usage of f-string is obvious.\n", | |
"\n", | |
"# Multi-line single quote usage.\n", | |
"\n", | |
"long_string = \"Transaction isolation in PostgreSQL have 4 levels. They are—Read Uncommitted, Read Committed, Repeatable Read, and Serializable.\"\n", | |
"\n", | |
"# This makes the string multi line, but sometimes that's not what we want.\n", | |
"long_string_pro = \"\"\"\n", | |
"...\n", | |
"\"\"\"\n", | |
"\n", | |
"# This one is more suitable when you still want the result to appear in a single line\n", | |
"long_string_pro_max = ('Transaction isolation in PostgreSQL have 4 levels.'\n", | |
" 'They are—Read Uncommitted, Read Committed, Repeatable Read,'\n", | |
" 'and Serializable.')\n", | |
"\n", | |
"\n", | |
"\n", | |
"print(long_string_pro_max)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"id": "ea918633", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Type hints.\n", | |
"from __future__ import annotations\n", | |
"\n", | |
"# Nope...\n", | |
"from typing import Callable, Iterable\n", | |
"\n", | |
"# Yep..\n", | |
"from collections.abc import Callable, Iterable, MutableMapping\n", | |
"\n", | |
"\n", | |
"def f(dct:dict, \n", | |
" list_of_tuple_of_str: list[tuple[str, ...]],\n", | |
" func: Callable[..., None] | None = None,\n", | |
" ) -> None:\n", | |
" pass" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"id": "c4b5eb18", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Consistent comment with proper grammar. Golang enforces this for public functions.\n", | |
"\n", | |
"# Sphinx style.\n", | |
"\n", | |
"class Foo:\n", | |
" \"\"\"[Summary]\n", | |
"\n", | |
" :param [ParamName]: [ParamDescription], defaults to [DefaultParamVal]\n", | |
" :type [ParamName]: [ParamType](, optional)\n", | |
" ...\n", | |
" :raises [ErrorType]: [ErrorDescription]\n", | |
" ...\n", | |
" :return: [ReturnDescription]\n", | |
" :rtype: [ReturnType]\n", | |
" \"\"\"\n", | |
"\n", | |
"# Numpy Style.\n", | |
"class Bar:\n", | |
" \"\"\"A dummy class for demo.\n", | |
" \n", | |
" Parameters\n", | |
" ----------\n", | |
" x : type\n", | |
" Description of parameter `x`.\n", | |
" y\n", | |
" Description of parameter `y` (with type not specified).\n", | |
" \n", | |
"\n", | |
" Returns\n", | |
" -------\n", | |
" err_code : int\n", | |
" Non-zero value indicates error code, or zero on success.\n", | |
" err_msg : str or None\n", | |
" Human readable error message, or None on success.\n", | |
" \n", | |
" \"\"\"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "a4732a0b", | |
"metadata": {}, | |
"source": [ | |
"## Resources" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "299da133", | |
"metadata": {}, | |
"source": [ | |
"1. [Super considered super - Raymond Hettinger](https://www.youtube.com/watch?v=xKgELVmrqfs)\n", | |
"\n", | |
"2. [Auto upgrading python syntaxes via Pyupgrade](https://github.com/asottile/pyupgrade)\n", | |
"\n", | |
"3. [Add trailing commas](https://github.com/asottile/add-trailing-comma)\n", | |
"\n", | |
"4. [Numpy docstring format](https://numpydoc.readthedocs.io/en/latest/format.html)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "b092c965", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "09b2109e", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "e515715d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "a86977ae", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.9.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment