Leave the SimpleIO.input_optional out of the input


#21

Yes, the skip_empty_keys attribute, but only for the output, as you said. Would you have the same parameter affect the input as well, or rather go for a new attribute, say skip_empty_input, to separate the two functionalities?


#22

Please add skip_empty_keys for now - I am a bit reluctant to add more parameters until SimpleIO can be refactored, which is not something that will happen soon.

In the next release, we can have:

  • skip_empty_request_keys = True/False or [a list, of keys, to skip]
  • skip_empty_response_keys = True/False or [a list, of keys, to skip]
  • skip_empty_keys = True/False or [a list, of keys, to skip, both in request and response]

I would also like to find a way to express it as such:

from mymodel import UserModel # SQLAlchemy-based

class SimpleIO:
  input_required = UserModel - ('password', 'token_expiry')
  output_required = UserModel + 'current_node'

That would make it more readable than additional parameters to SimpleIO class. It would require for UserModel to subclass from our own wrapper around SQLAlchemy Table but the result could be very pleasing. This is something to experiment with.


#23

I started to refactor SimpleIO, here is the feature branch for it.

In the end, as far as empty keys or defaults go, it will be:

  • skip_empty_response_keys - which of optional output elements not to return if their values are not provided by users
  • skip_empty_request_keys = True/False or [a list, of keys, to skip] -> if something is not provided on input, then it will not exist in self.request.input at all, i.e. accessing it will raise a KeyError (or AttributeError, I’m not sure yet)
  • There will be a new object NotGiven that, unless skip_empty_request_keys is used, all optional input parameters will be assigned. This will let one check for existence of input elements using if self.request.input.user_id is NotGiven: ...
  • New options default_input_value and default_output_value will be used for default values, unless overridden on a per-element basis or unless optional elements are to be skipped per skip_* options

The whole effort will surely take a long time, for now I am just letting you know about how it will be possible to differentiate between actually missing or merely empty values.


#24

Hi, @dsuch! That sounds very good. Looking forward to it. :slight_smile: