https://dasgeld.co/posts/46BB9DE9-F787-4D68-B422-7151D124FB0E
https://dasgeld.co/posts/46BB9DE9-F787-4D68-B422-7151D124FB0E
@overload
def deser(data: bytes, disc: Literal['type1']) -> DeserializedType1: ...
and then anywhere the discriminant is provable, ...
@overload
def deser(data: bytes, disc: Literal['type1']) -> DeserializedType1: ...
and then anywhere the discriminant is provable, ...
It gives you a path towards defining defaults on TypedDict a la Annotated fields, so you can Unpack them into function signatures.
Getting this right _really_ lets you write OSS that folks can truly extend easily.
It gives you a path towards defining defaults on TypedDict a la Annotated fields, so you can Unpack them into function signatures.
Getting this right _really_ lets you write OSS that folks can truly extend easily.
Dataclasses let you add behavior like `.from_json()` and field validation (a la @attr.s) at runtime
Dataclasses let you add behavior like `.from_json()` and field validation (a la @attr.s) at runtime
from langchain_core.messages import AnyMessage
from langchain_core.messages.utils import count_tokens_approximately
from langmem.short_term import SummarizationNode
from langgraph.graph import StateGraph, START, MessagesState
from langchain_core.messages import AnyMessage
from langchain_core.messages.utils import count_tokens_approximately
from langmem.short_term import SummarizationNode
from langgraph.graph import StateGraph, START, MessagesState
class GreetingKwargs(TypedDict):
name: Annotated[str, Doc("the name of the person to greet")]
def greet(**kwargs […]
[Original post on scholar.social]
class GreetingKwargs(TypedDict):
name: Annotated[str, Doc("the name of the person to greet")]
def greet(**kwargs […]
[Original post on scholar.social]
class Things(TypedDict):
thing: Literal["thing-role"]
another_thing: Literal["another-role"]
How can I extract all the values so that they can be passed as a type for a function parameter? Is get_type_hints my only resort?
#python
class Things(TypedDict):
thing: Literal["thing-role"]
another_thing: Literal["another-role"]
How can I extract all the values so that they can be passed as a type for a function parameter? Is get_type_hints my only resort?
#python
Whenever I need to put a structure to a data I send to/get from an API, all I need to do is to cast() the variable into the suitable TypedDict or Protocol and off I go.
That flexibility is head and shoulders better than all the hoops I have to jump through in C#.
Whenever I need to put a structure to a data I send to/get from an API, all I need to do is to cast() the variable into the suitable TypedDict or Protocol and off I go.
That flexibility is head and shoulders better than all the hoops I have to jump through in C#.
#networkautomation
#networkautomation
Heckin hate it whenever I see a method that's like, "This takes a dictionary" and then I have to read the whole source just figure out what keys are expected.
Heckin hate it whenever I see a method that's like, "This takes a dictionary" and then I have to read the whole source just figure out what keys are expected.
Pydantic is a runtime validator, that ensures your data *actually* matches the declared types.
Pydantic is a runtime validator, that ensures your data *actually* matches the declared types.
#python #learntocode #techblog #programming
hevalhazalkurt.com/blog/datacla...
#python #learntocode #techblog #programming
hevalhazalkurt.com/blog/datacla...