diff --git a/posts/concatenate.md b/posts/concatenate.md index 0220d52..807ffe7 100644 --- a/posts/concatenate.md +++ b/posts/concatenate.md @@ -1,5 +1,6 @@ --- author: orsinium +id: 730 published: 2023-08-10 topics: - typing diff --git a/posts/param-spec.md b/posts/param-spec.md index d2356ec..113e509 100644 --- a/posts/param-spec.md +++ b/posts/param-spec.md @@ -1,5 +1,6 @@ --- author: orsinium +id: 729 published: 2023-08-08 topics: - typing diff --git a/posts/type-params.md b/posts/type-params.md new file mode 100644 index 0000000..962132e --- /dev/null +++ b/posts/type-params.md @@ -0,0 +1,64 @@ +--- +author: orsinium +published: 2023-08-17 +pep: 695 +python: "3.12" +topics: + - typing +--- + +# Type parameter syntax + +[PEP 695](https://peps.python.org/pep-0695/) (will land in Python 3.12) introduced a new, more concise, way to declare type parameters. + +Before: + +```python +from typing import Generic, Iterable, TypeVar + +T = TypeVar('T') + +def max(args: Iterable[T]) -> T: + ... + +class Queue(Generic[T]): + def push(self, item: T) -> None: + ... +``` + +After: + +```python +from typing import Iterable + +def max[T](args: Iterable[T]) -> T: + ... + +class Queue[T]: + def push(self, item: T) -> None: + ... +``` + +And you can also add constraints to type variables. + +Before: + +```python +from typing import Callable, TypeVar + +C = TypeVar('C', bound=Callable) + +def decorator(f: C) -> C: + ... +``` + +After: + +```python +from typing import Callable + +def decorator[C: (Callable, )](f: C) -> C: + ... +``` + +The main benefit of the new syntax is that type constraints are now scoped to the class or function that uses them. The old `TypeVar` syntax made you declare a global variable at the top of the file that might be far from the class or function declaration that needs them and is often reused in multiple places. diff --git a/posts/typed-dict.md b/posts/typed-dict.md index 35f3ca2..2729d84 100644 --- a/posts/typed-dict.md +++ b/posts/typed-dict.md @@ -2,6 +2,8 @@ published: 2021-03-25 id: 656 author: orsinium +topics: + - typing traces: - [module: typing, type: TypedDict] pep: 589 diff --git a/posts/typing-self.md b/posts/typing-self.md index f7aae2a..0eb05f4 100644 --- a/posts/typing-self.md +++ b/posts/typing-self.md @@ -2,6 +2,8 @@ author: orsinium id: 711 published: 2022-12-03 +topics: + - typing traces: - [module: typing, type: Self] pep: 673 diff --git a/posts/website-announcement.md b/posts/website-announcement.md new file mode 100644 index 0000000..36dd72c --- /dev/null +++ b/posts/website-announcement.md @@ -0,0 +1,14 @@ +--- +author: orsinium +published: 2023-08-15 +--- + +# Website announcement + +Great news everyone! We extracted all our recent posts as Markdown, organized them, and made them more accessible. Now we have: + +* 🌐 Website: [pythonetc.orsinium.dev](https://pythonetc.orsinium.dev/) +* 📢 RSS: [pythonetc.orsinium.dev/index.xml](https://pythonetc.orsinium.dev/index.xml) +* 🧑‍💻️ GitHub: [github.com/life4/pythonetc](https://github.com/life4/pythonetc) + +If you want to write a guest post, just send us a PR on GitHub. The README tells what you can write about and how. Thank you all for staying with us all these years ❤️ diff --git a/todo.md b/todo.md index fe8c629..5eaa962 100644 --- a/todo.md +++ b/todo.md @@ -60,4 +60,5 @@ These are ideas for future posts. Let me know if you want to write a guest post + asyncio.TaskGroup + contextvars + itertools.pairwise ++ typing.deprecated +