nonlocal in Python 3#TIL about nonlocal in Python 3 Inner functions can access outer variables but can’t modify them by default Here’s a contrived simple example def outer(): num = 0 def inner(): nonlocal num num += 1 inner() If you remove t...Aug 28, 2025·1 min read
Useful lesser known Python typesFinal from typing import Final _PI: Final[float] = 3.14 Hashable from typing import Any, Dict from collections.abc import Hashable my_dict: Dict[Hashable, Any] TypedDict # Python >= 3.11 from typing import Optional, NotRequired, TypedDict # Pyth...Apr 19, 2024·1 min read
Column select in terminalsSelect columns in a terminal eg: select only the pids VSCode terminal : alt/option + click and drag iTerm: ⌘ + alt / ⌥ + click and drag https://www.youtube.com/watch?v=v1Y7aoRnWdAApr 19, 2024·1 min read
unittest param order is the opposite of Jestwhich is the opposite order for Jestexpect(myVar).toBe(42) assumes the first is expected, second is actual in the error message. self.assertEqual(expected, actual) self.assertEqual(42, my_var) PyCharm even displays Expected and Actual Failure Expect...Apr 19, 2024·1 min read
Prevent global `pip install`PIP_REQUIRE_VIRTUALENV=truein your .zshrc (or env variables) prevents you from pip installing globally so that you only run pip install in a venv Only use pipx for global installsMar 7, 2024·1 min read
VSCode: move snippet suggestions to the bottomProblem In VSCode, when I trigger suggestions (with Ctrl space), it would show snippet suggestions at the top Instead of showing me possible parameter options Solution TIL You can move snippet suggestions to the bottom (or inline) so that suggesti...Jan 26, 2024·1 min read
Trigger an ESLint error if you leave a function in the codeESLint can give an error if you leave a console.log or console.error in your codebase. We can do the same with any other function! Example: suppress console const suppressConsoleWarnAndError = () => { const consoleErrorSpy = jest.spyOn(console, 'er...Jan 26, 2024·1 min read