From ee32b73efc8cd7c4d414cd286e21feeae92e0d4a Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld <62857+pydanny@users.noreply.github.com> Date: Tue, 11 Jun 2024 18:06:28 +0100 Subject: [PATCH] Update BJJ --- pages/about.mdoc | 2 +- public/feeds/atom.xml | 95 ++++++++++++++++++++++-------------- public/feeds/django.atom.xml | 2 +- public/feeds/python.atom.xml | 2 +- public/feeds/til.atom.xml | 95 ++++++++++++++++++++++-------------- 5 files changed, 121 insertions(+), 75 deletions(-) diff --git a/pages/about.mdoc b/pages/about.mdoc index 001f4b9..49e973c 100644 --- a/pages/about.mdoc +++ b/pages/about.mdoc @@ -10,7 +10,7 @@ I am a [coder](https://github.com/pydanny), [author](/books), and [speaker](/spe I'm probably best known as "[pydanny](https://www.google.com/search?q=pydanny)", one of the authors of [Two Scoops of Django](/books/tech). -I love to hang out with my [wife](https://audrey.feldroy.com/), play with my [daughter](/tags/uma), do [Brazilian Jiu-Jitsu](https://en.wikipedia.org/wiki/Brazilian_jiu-jitsu), write [books](/books), and read books. I work at [Kraken Tech](https://kraken.tech/), a company that is part of the sustainable global energy [Octopus Energy Group](https://octopusenergy.group/) working to address [global climate change](/tags/climate-change). +I love to hang out with my [wife](https://audrey.feldroy.com/), play with my [daughter](/tags/uma), do [Brazilian Jiu-Jitsu](https://en.wikipedia.org/wiki/Brazilian_jiu-jitsu) at [Apex BJJ](https://www.apexbjj.co.uk/) in London, write [books](/books), and read books. I work at [Kraken Tech](https://kraken.tech/), a company that is part of the sustainable global energy [Octopus Energy Group](https://octopusenergy.group/) working to address [global climate change](/tags/climate-change). - [Mastodon](https://fosstodon.org/@danielfeldroy) - [LinkedIn](https://www.linkedin.com/in/danielfeldroy/) diff --git a/public/feeds/atom.xml b/public/feeds/atom.xml index 930f49d..b424a85 100644 --- a/public/feeds/atom.xml +++ b/public/feeds/atom.xml @@ -2,7 +2,7 @@ https://daniel.feldroy.com/ Daniel Roy Greenfeld - 2024-06-04T13:23:23.887Z + 2024-06-11T17:05:52.638Z Next.js using Feed for Node.js Daniel Roy Greenfeld @@ -14,6 +14,64 @@ https://daniel.feldroy.com/images/pydanny-cartwheel.png https://daniel.feldroy.com/favicon.ico All rights reserved 2024, Daniel Roy Greenfeld + + <![CDATA[TIL: Passing exceptions as arguments in Python]]> + https://daniel.feldroy.com/posts/til-2024-06-passing-exceptions-as-arguments-in-python + + 2024-06-07T10:13:05.553Z + + Mypy needs an extra identifier to not choke on an exception passed as an argument.

+

This will throw a mypy error:

+
# code.py
+class MyException(Exception):
+    pass
+
+
+def myfunc(custom_exception: Exception) -> None:
+    try:
+        print('Test')
+    except custom_exception:
+        print('error)
+
+myfunc(MyException)
+
+

The error mypy will throw looks something like this:

+
$ mypy code.py
+
+code.py:6: error: Exception type must be derived from BaseException (or be a tuple of exception classes)  [misc]
+code.py:9: error: Argument 1 to "custom_exception" has incompatible type "type[MyException]"; expected "Exception"  [arg-type]
+Found 2 errors in 1 file (checked 1 source file)
+
+

The solution is to use typing.Type:

+
# code.py
+from typing import Type
+
+
+class MyException(Exception):
+    pass
+
+
+def myfunc(custom_exception: Type[Exception]) -> None:
+    try:
+        print('Test')
+    except custom_exception:
+        print('error)
+
+myfunc(MyException)
+
+]]>
+ + Daniel Roy Greenfeld + daniel@feldroy.com + https://daniel.feldroy.com + + + + Daniel Roy Greenfeld + daniel@feldroy.com + https://daniel.feldroy.com + +
<![CDATA[TIL: Renaming git branches]]> https://daniel.feldroy.com/posts/til-2024-06-renaming-git-branches @@ -117,39 +175,4 @@ class Command(BaseCommand): https://daniel.feldroy.com - - <![CDATA[TIL: Auto setup remote branch for git]]> - https://daniel.feldroy.com/posts/til-2024-05-auto-setup-remote-branch-for-git - - 2024-05-21T08:38:05.180Z - - For getting rid of the "fatal: The current branch new-awesome-feature has no upstream branch" error.

-

Whenever I create a new branch and try to push the new commit then I start seeing this error:

-
git push --force
-fatal: The current branch new-awesome-feature has no upstream branch.
-To push the current branch and set the remote as upstream, use
-
-    git push --set-upstream origin new-awesome-feature
-
-To have this happen automatically for branches without a tracking
-upstream, see 'push.autoSetupRemote' in 'git help config'.
-
-

To fix it so git just auto creates the branch, just enter this magic command:

-
git config --global --add --bool push.autoSetupRemote true
-
-]]>
- - Daniel Roy Greenfeld - daniel@feldroy.com - https://daniel.feldroy.com - - - - - - Daniel Roy Greenfeld - daniel@feldroy.com - https://daniel.feldroy.com - -
\ No newline at end of file diff --git a/public/feeds/django.atom.xml b/public/feeds/django.atom.xml index b5a0cf8..4087cb5 100644 --- a/public/feeds/django.atom.xml +++ b/public/feeds/django.atom.xml @@ -2,7 +2,7 @@ https://daniel.feldroy.com/ Daniel Roy Greenfeld - 2024-06-04T13:23:23.802Z + 2024-06-11T17:05:52.549Z Next.js using Feed for Node.js Daniel Roy Greenfeld diff --git a/public/feeds/python.atom.xml b/public/feeds/python.atom.xml index 17ebcc6..89e38ba 100644 --- a/public/feeds/python.atom.xml +++ b/public/feeds/python.atom.xml @@ -2,7 +2,7 @@ https://daniel.feldroy.com/ Daniel Roy Greenfeld - 2024-06-04T13:23:23.831Z + 2024-06-11T17:05:52.574Z Next.js using Feed for Node.js Daniel Roy Greenfeld diff --git a/public/feeds/til.atom.xml b/public/feeds/til.atom.xml index 8ddbae9..aa90dbe 100644 --- a/public/feeds/til.atom.xml +++ b/public/feeds/til.atom.xml @@ -2,7 +2,7 @@ https://daniel.feldroy.com/ Daniel Roy Greenfeld - 2024-06-04T13:23:23.855Z + 2024-06-11T17:05:52.603Z Next.js using Feed for Node.js Daniel Roy Greenfeld @@ -14,6 +14,64 @@ https://daniel.feldroy.com/images/pydanny-cartwheel.png https://daniel.feldroy.com/favicon.ico All rights reserved 2024, Daniel Roy Greenfeld + + <![CDATA[TIL: Passing exceptions as arguments in Python]]> + https://daniel.feldroy.com/posts/til-2024-06-passing-exceptions-as-arguments-in-python + + 2024-06-07T10:13:05.553Z + + Mypy needs an extra identifier to not choke on an exception passed as an argument.

+

This will throw a mypy error:

+
# code.py
+class MyException(Exception):
+    pass
+
+
+def myfunc(custom_exception: Exception) -> None:
+    try:
+        print('Test')
+    except custom_exception:
+        print('error)
+
+myfunc(MyException)
+
+

The error mypy will throw looks something like this:

+
$ mypy code.py
+
+code.py:6: error: Exception type must be derived from BaseException (or be a tuple of exception classes)  [misc]
+code.py:9: error: Argument 1 to "custom_exception" has incompatible type "type[MyException]"; expected "Exception"  [arg-type]
+Found 2 errors in 1 file (checked 1 source file)
+
+

The solution is to use typing.Type:

+
# code.py
+from typing import Type
+
+
+class MyException(Exception):
+    pass
+
+
+def myfunc(custom_exception: Type[Exception]) -> None:
+    try:
+        print('Test')
+    except custom_exception:
+        print('error)
+
+myfunc(MyException)
+
+]]>
+ + Daniel Roy Greenfeld + daniel@feldroy.com + https://daniel.feldroy.com + + + + Daniel Roy Greenfeld + daniel@feldroy.com + https://daniel.feldroy.com + +
<![CDATA[TIL: Renaming git branches]]> https://daniel.feldroy.com/posts/til-2024-06-renaming-git-branches @@ -50,39 +108,4 @@ https://daniel.feldroy.com - - <![CDATA[TIL: Auto setup remote branch for git]]> - https://daniel.feldroy.com/posts/til-2024-05-auto-setup-remote-branch-for-git - - 2024-05-21T08:38:05.180Z - - For getting rid of the "fatal: The current branch new-awesome-feature has no upstream branch" error.

-

Whenever I create a new branch and try to push the new commit then I start seeing this error:

-
git push --force
-fatal: The current branch new-awesome-feature has no upstream branch.
-To push the current branch and set the remote as upstream, use
-
-    git push --set-upstream origin new-awesome-feature
-
-To have this happen automatically for branches without a tracking
-upstream, see 'push.autoSetupRemote' in 'git help config'.
-
-

To fix it so git just auto creates the branch, just enter this magic command:

-
git config --global --add --bool push.autoSetupRemote true
-
-]]>
- - Daniel Roy Greenfeld - daniel@feldroy.com - https://daniel.feldroy.com - - - - - - Daniel Roy Greenfeld - daniel@feldroy.com - https://daniel.feldroy.com - -
\ No newline at end of file