on-internet
← Community

Python type hint for undefined values to distinguish from None

Stack Overflow ·

I want to create a function signature where an undefined value and None are distinct from each other. So e.g.: undefined = object() def update(id: str, title: str = undefined, description: str): data = { "title": title, "description": description, } # remove undefined key-value pairs from data for key in data.keys(): if data[key] is undefined: del data[key] # send data to the server for further processing Obviously this way I get conflicting types and the following error: Incompatible default for argument "description" (default has type "object", argument has type "str") From the above example

Comments

Sign in or sign up to comment and upvote.

No comments yet.