-
Hello, As the title says, what is the purpose of the UNSET constant / class ? As a beginner I'm really confused by it. I apologize in advance if this question already has answers / this is not the appropriate place to ask it, please redirect me if that's the case ! Thanks :) Simon |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hiya @skpn! The Simple AnswerThere are really two answers to this question, so let's start with the simple one. The Complicated AnswerThe more complicated answer has to do with how OpenAPI allows you to define values. There are a bunch of different attributes you can use to describe how a particular value should be used, but the relevant ones here are Let's take the example of a theoretical OpenAPI document describing how to manage issues on GitHub. If you are going to create a new issue, there are going to be some required parameters (e.g. So how do we represent that in Python? How do we make sure that we're only sending values to the API that the consumer wants to send? We solved this by adding a default value called There are a few other common patterns for handling this problem in Python, the most popular is to default to How Do Other Libraries Do It?Basically like this. If you use |
Beta Was this translation helpful? Give feedback.
Hiya @skpn!
The Simple Answer
There are really two answers to this question, so let's start with the simple one.
UNSET
is a sentinel object of typeUnset
. We use it in generated clients to determine whether or not a value was passed to a function or class. If you're familiar with JavaScript, this is basically equivalent toundefined
, it's just that Python does not give us a built-in way to represent that concept, so libraries have to include their own.The Complicated Answer
The more complicated answer has to do with how OpenAPI allows you to define values. There are a bunch of different attributes you can use to describe how a particular value should be used, but the relevant ones here are