From bac8a5d2822835cf47175d1162030653fadd5c09 Mon Sep 17 00:00:00 2001 From: johannst Date: Thu, 15 Feb 2024 23:29:57 +0000 Subject: deploy: 4485708c972815bbb6df7f5a228683aa855d553d --- development/python.html | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'development/python.html') diff --git a/development/python.html b/development/python.html index 5d15d0d..4aa6ff9 100644 --- a/development/python.html +++ b/development/python.html @@ -183,26 +183,26 @@ def log(f: Callable[[int], None]) -> Callable[[int], None]: def inner(x: int): - print(f"log::inner f={f.__name__} x={x}") + print(f"log::inner f={f.__name__} x={x}") f(x) return inner @log def some_fn(x: int): - print(f"some_fn x={x}") + print(f"some_fn x={x}") def log_tag(tag: str) -> Callable[[Callable[[int], None]], Callable[[int], None]]: def decorator(f: Callable[[int], None]) -> Callable[[int], None]: def inner(x: int): - print(f"log_tag::inner f={f.__name__} tag={tag} x={x}") + print(f"log_tag::inner f={f.__name__} tag={tag} x={x}") f(x) return inner return decorator -@log_tag("some_tag") +@log_tag("some_tag") def some_fn2(x: int): - print(f"some_fn2 x={x}") + print(f"some_fn2 x={x}")

Walrus operator [run]

Walrus operator := added since python 3.8.

@@ -214,20 +214,20 @@ def foo(ret: Optional[int]) -> Optional[int]: return ret if r := foo(None): - print(f"foo(None) -> {r}") + print(f"foo(None) -> {r}") if r := foo(1337): - print(f"foo(1337) -> {r}") + print(f"foo(1337) -> {r}") # Example 2: while let statements toks = iter(['a', 'b', 'c']) while tok := next(toks, None): - print(f"{tok}") + print(f"{tok}") # Example 3: list comprehension -print([tok for t in [" a", " ", " b "] if (tok := t.strip())]) +print([tok for t in [" a", " ", " b "] if (tok := t.strip())])

Unittest [run]

Run unittests directly from the command line as
@@ -255,19 +255,19 @@ class MyTest(unittest.TestCase):

# file: test.py
 
 def sum(a: int, b: int) -> int:
-    """Sum a and b.
+    """Sum a and b.
 
     >>> sum(1, 2)
     3
 
     >>> sum(10, 20)
     30
-    """
+    """
     return a + b
 

timeit

Micro benchmarking.

-
python -m timeit '[x.strip() for x in ["a ", " b"]]'
+
python -m timeit '[x.strip() for x in ["a ", " b"]]'
 
-- cgit v1.2.3