aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ChrisJL <[email protected]>2022-04-03 19:32:43 +0100
committerGravatar GitHub <[email protected]>2022-04-03 19:32:43 +0100
commitf0bfa41226c2e89440e8acfee2181d67369ce840 (patch)
treebb03f53dcf7d8850aa9af4a53955146a34b7a3b1
parentMerge pull request #2069 from GDWR/feature/ping_on_bad_words_in_username (diff)
parentMerge branch 'main' into type-hint-tag (diff)
Merge pull request #1943 from jonathan-d-zhang/type-hint-tag
Make type-hint tag
-rw-r--r--bot/resources/tags/type-hint.md19
1 files changed, 19 insertions, 0 deletions
diff --git a/bot/resources/tags/type-hint.md b/bot/resources/tags/type-hint.md
new file mode 100644
index 000000000..f4a12f125
--- /dev/null
+++ b/bot/resources/tags/type-hint.md
@@ -0,0 +1,19 @@
+**Type Hints**
+
+A type hint indicates what type a variable is expected to be.
+```python
+def add(a: int, b: int) -> int:
+ return a + b
+```
+The type hints indicate that for our `add` function the parameters `a` and `b` should be integers, and the function should return an integer when called.
+
+It's important to note these are just hints and are not enforced at runtime.
+
+```python
+add("hello ", "world")
+```
+The above code won't error even though it doesn't follow the function's type hints; the two strings will be concatenated as normal.
+
+Third party tools like [mypy](https://mypy.readthedocs.io/en/stable/introduction.html) can validate your code to ensure it is type hinted correctly. This can help you identify potentially buggy code, for example it would error on the second example as our `add` function is not intended to concatenate strings.
+
+[mypy's documentation](https://mypy.readthedocs.io/en/stable/builtin_types.html) contains useful information on type hinting, and for more information check out [this documentation page](https://typing.readthedocs.io/en/latest/index.html).