-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
121 additions
and
75 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
<feed xmlns="http://www.w3.org/2005/Atom"> | ||
<id>https://daniel.feldroy.com/</id> | ||
<title>Daniel Roy Greenfeld</title> | ||
<updated>2024-06-04T13:23:23.887Z</updated> | ||
<updated>2024-06-11T17:05:52.638Z</updated> | ||
<generator>Next.js using Feed for Node.js</generator> | ||
<author> | ||
<name>Daniel Roy Greenfeld</name> | ||
|
@@ -14,6 +14,64 @@ | |
<logo>https://daniel.feldroy.com/images/pydanny-cartwheel.png</logo> | ||
<icon>https://daniel.feldroy.com/favicon.ico</icon> | ||
<rights>All rights reserved 2024, Daniel Roy Greenfeld</rights> | ||
<entry> | ||
<title type="html"><![CDATA[TIL: Passing exceptions as arguments in Python]]></title> | ||
<id>https://daniel.feldroy.com/posts/til-2024-06-passing-exceptions-as-arguments-in-python</id> | ||
<link href="https://daniel.feldroy.com/posts/til-2024-06-passing-exceptions-as-arguments-in-python"/> | ||
<updated>2024-06-07T10:13:05.553Z</updated> | ||
<summary type="html"><![CDATA[Mypy needs an extra identifier to not choke on an exception passed as an argument.]]></summary> | ||
<content type="html"><![CDATA[<p><em>Mypy needs an extra identifier to not choke on an exception passed as an argument.</em></p> | ||
<p>This will throw a mypy error:</p> | ||
<pre><code class="language-python"># code.py | ||
class MyException(Exception): | ||
pass | ||
def myfunc(custom_exception: Exception) -> None: | ||
try: | ||
print('Test') | ||
except custom_exception: | ||
print('error) | ||
myfunc(MyException) | ||
</code></pre> | ||
<p>The error mypy will throw looks something like this:</p> | ||
<pre><code class="language-bash">$ 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) | ||
</code></pre> | ||
<p>The solution is to use <code>typing.Type</code>:</p> | ||
<pre><code class="language-python"># 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) | ||
</code></pre> | ||
]]></content> | ||
<author> | ||
<name>Daniel Roy Greenfeld</name> | ||
<email>[email protected]</email> | ||
<uri>https://daniel.feldroy.com</uri> | ||
</author> | ||
<category term="TIL"/> | ||
<contributor> | ||
<name>Daniel Roy Greenfeld</name> | ||
<email>[email protected]</email> | ||
<uri>https://daniel.feldroy.com</uri> | ||
</contributor> | ||
</entry> | ||
<entry> | ||
<title type="html"><![CDATA[TIL: Renaming git branches]]></title> | ||
<id>https://daniel.feldroy.com/posts/til-2024-06-renaming-git-branches</id> | ||
|
@@ -117,39 +175,4 @@ class Command(BaseCommand): | |
<uri>https://daniel.feldroy.com</uri> | ||
</contributor> | ||
</entry> | ||
<entry> | ||
<title type="html"><![CDATA[TIL: Auto setup remote branch for git]]></title> | ||
<id>https://daniel.feldroy.com/posts/til-2024-05-auto-setup-remote-branch-for-git</id> | ||
<link href="https://daniel.feldroy.com/posts/til-2024-05-auto-setup-remote-branch-for-git"/> | ||
<updated>2024-05-21T08:38:05.180Z</updated> | ||
<summary type="html"><![CDATA[For getting rid of the "fatal: The current branch new-awesome-feature has no upstream branch" error.]]></summary> | ||
<content type="html"><![CDATA[<p><em>For getting rid of the "fatal: The current branch new-awesome-feature has no upstream branch" error.</em></p> | ||
<p>Whenever I create a new branch and try to push the new commit then I start seeing this error:</p> | ||
<pre><code>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'. | ||
</code></pre> | ||
<p>To fix it so git just auto creates the branch, just enter this magic command:</p> | ||
<pre><code class="language-bash">git config --global --add --bool push.autoSetupRemote true | ||
</code></pre> | ||
]]></content> | ||
<author> | ||
<name>Daniel Roy Greenfeld</name> | ||
<email>[email protected]</email> | ||
<uri>https://daniel.feldroy.com</uri> | ||
</author> | ||
<category term="TIL"/> | ||
<category term="git"/> | ||
<category term="howto"/> | ||
<contributor> | ||
<name>Daniel Roy Greenfeld</name> | ||
<email>[email protected]</email> | ||
<uri>https://daniel.feldroy.com</uri> | ||
</contributor> | ||
</entry> | ||
</feed> |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
<feed xmlns="http://www.w3.org/2005/Atom"> | ||
<id>https://daniel.feldroy.com/</id> | ||
<title>Daniel Roy Greenfeld</title> | ||
<updated>2024-06-04T13:23:23.855Z</updated> | ||
<updated>2024-06-11T17:05:52.603Z</updated> | ||
<generator>Next.js using Feed for Node.js</generator> | ||
<author> | ||
<name>Daniel Roy Greenfeld</name> | ||
|
@@ -14,6 +14,64 @@ | |
<logo>https://daniel.feldroy.com/images/pydanny-cartwheel.png</logo> | ||
<icon>https://daniel.feldroy.com/favicon.ico</icon> | ||
<rights>All rights reserved 2024, Daniel Roy Greenfeld</rights> | ||
<entry> | ||
<title type="html"><![CDATA[TIL: Passing exceptions as arguments in Python]]></title> | ||
<id>https://daniel.feldroy.com/posts/til-2024-06-passing-exceptions-as-arguments-in-python</id> | ||
<link href="https://daniel.feldroy.com/posts/til-2024-06-passing-exceptions-as-arguments-in-python"/> | ||
<updated>2024-06-07T10:13:05.553Z</updated> | ||
<summary type="html"><![CDATA[Mypy needs an extra identifier to not choke on an exception passed as an argument.]]></summary> | ||
<content type="html"><![CDATA[<p><em>Mypy needs an extra identifier to not choke on an exception passed as an argument.</em></p> | ||
<p>This will throw a mypy error:</p> | ||
<pre><code class="language-python"># code.py | ||
class MyException(Exception): | ||
pass | ||
def myfunc(custom_exception: Exception) -> None: | ||
try: | ||
print('Test') | ||
except custom_exception: | ||
print('error) | ||
myfunc(MyException) | ||
</code></pre> | ||
<p>The error mypy will throw looks something like this:</p> | ||
<pre><code class="language-bash">$ 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) | ||
</code></pre> | ||
<p>The solution is to use <code>typing.Type</code>:</p> | ||
<pre><code class="language-python"># 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) | ||
</code></pre> | ||
]]></content> | ||
<author> | ||
<name>Daniel Roy Greenfeld</name> | ||
<email>[email protected]</email> | ||
<uri>https://daniel.feldroy.com</uri> | ||
</author> | ||
<category term="TIL"/> | ||
<contributor> | ||
<name>Daniel Roy Greenfeld</name> | ||
<email>[email protected]</email> | ||
<uri>https://daniel.feldroy.com</uri> | ||
</contributor> | ||
</entry> | ||
<entry> | ||
<title type="html"><![CDATA[TIL: Renaming git branches]]></title> | ||
<id>https://daniel.feldroy.com/posts/til-2024-06-renaming-git-branches</id> | ||
|
@@ -50,39 +108,4 @@ | |
<uri>https://daniel.feldroy.com</uri> | ||
</contributor> | ||
</entry> | ||
<entry> | ||
<title type="html"><![CDATA[TIL: Auto setup remote branch for git]]></title> | ||
<id>https://daniel.feldroy.com/posts/til-2024-05-auto-setup-remote-branch-for-git</id> | ||
<link href="https://daniel.feldroy.com/posts/til-2024-05-auto-setup-remote-branch-for-git"/> | ||
<updated>2024-05-21T08:38:05.180Z</updated> | ||
<summary type="html"><![CDATA[For getting rid of the "fatal: The current branch new-awesome-feature has no upstream branch" error.]]></summary> | ||
<content type="html"><![CDATA[<p><em>For getting rid of the "fatal: The current branch new-awesome-feature has no upstream branch" error.</em></p> | ||
<p>Whenever I create a new branch and try to push the new commit then I start seeing this error:</p> | ||
<pre><code>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'. | ||
</code></pre> | ||
<p>To fix it so git just auto creates the branch, just enter this magic command:</p> | ||
<pre><code class="language-bash">git config --global --add --bool push.autoSetupRemote true | ||
</code></pre> | ||
]]></content> | ||
<author> | ||
<name>Daniel Roy Greenfeld</name> | ||
<email>[email protected]</email> | ||
<uri>https://daniel.feldroy.com</uri> | ||
</author> | ||
<category term="TIL"/> | ||
<category term="git"/> | ||
<category term="howto"/> | ||
<contributor> | ||
<name>Daniel Roy Greenfeld</name> | ||
<email>[email protected]</email> | ||
<uri>https://daniel.feldroy.com</uri> | ||
</contributor> | ||
</entry> | ||
</feed> |