Merge pull request #2913 from polkapolka/DigitalInOutTypeHints

Digital In Out Type Hints
This commit is contained in:
Jeff Epler 2020-05-17 12:37:04 -05:00 committed by GitHub
commit e51822133f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,7 +71,7 @@ STATIC mp_obj_t digitalio_digitalinout_make_new(const mp_obj_type_t *type,
return MP_OBJ_FROM_PTR(self); return MP_OBJ_FROM_PTR(self);
} }
//| def deinit(self, ) -> Any: //| def deinit(self) -> None:
//| """Turn off the DigitalInOut and release the pin for other use.""" //| """Turn off the DigitalInOut and release the pin for other use."""
//| ... //| ...
//| //|
@ -82,13 +82,13 @@ STATIC mp_obj_t digitalio_digitalinout_obj_deinit(mp_obj_t self_in) {
} }
MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_deinit_obj, digitalio_digitalinout_obj_deinit); MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_deinit_obj, digitalio_digitalinout_obj_deinit);
//| def __enter__(self, ) -> Any: //| def __enter__(self, ) -> DigitalInOut:
//| """No-op used by Context Managers.""" //| """No-op used by Context Managers."""
//| ... //| ...
//| //|
// Provided by context manager helper. // Provided by context manager helper.
//| def __exit__(self, ) -> Any: //| def __exit__(self, ) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See //| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info.""" //| :ref:`lifetime-and-contextmanagers` for more info."""
//| ... //| ...
@ -106,12 +106,13 @@ STATIC void check_for_deinit(digitalio_digitalinout_obj_t *self) {
} }
} }
//| def switch_to_output(self, value: bool = False, drive_mode: digitalio.DriveMode = digitalio.DriveMode.PUSH_PULL) -> Any: //| def switch_to_output(self, value: bool = False, drive_mode: digitalio.DriveMode = digitalio.DriveMode.PUSH_PULL) -> None:
//| """Set the drive mode and value and then switch to writing out digital //| """Set the drive mode and value and then switch to writing out digital
//| values. //| values.
//| //|
//| :param bool value: default value to set upon switching //| :param bool value: default value to set upon switching
//| :param ~digitalio.DriveMode drive_mode: drive mode for the output""" //| :param ~digitalio.DriveMode drive_mode: drive mode for the output
//| """
//| ... //| ...
//| //|
STATIC mp_obj_t digitalio_digitalinout_switch_to_output(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC mp_obj_t digitalio_digitalinout_switch_to_output(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@ -135,7 +136,7 @@ STATIC mp_obj_t digitalio_digitalinout_switch_to_output(size_t n_args, const mp_
} }
MP_DEFINE_CONST_FUN_OBJ_KW(digitalio_digitalinout_switch_to_output_obj, 1, digitalio_digitalinout_switch_to_output); MP_DEFINE_CONST_FUN_OBJ_KW(digitalio_digitalinout_switch_to_output_obj, 1, digitalio_digitalinout_switch_to_output);
//| def switch_to_input(self, pull: Pull = None) -> Any: //| def switch_to_input(self, pull: Pull = None) -> None:
//| """Set the pull and then switch to read in digital values. //| """Set the pull and then switch to read in digital values.
//| //|
//| :param Pull pull: pull configuration for the input //| :param Pull pull: pull configuration for the input
@ -162,6 +163,7 @@ STATIC mp_obj_t digitalio_digitalinout_switch_to_input(size_t n_args, const mp_o
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
digitalio_pull_t pull = PULL_NONE; digitalio_pull_t pull = PULL_NONE;
if (args[ARG_pull].u_rom_obj == &digitalio_pull_up_obj) { if (args[ARG_pull].u_rom_obj == &digitalio_pull_up_obj) {
pull = PULL_UP; pull = PULL_UP;
@ -174,7 +176,7 @@ STATIC mp_obj_t digitalio_digitalinout_switch_to_input(size_t n_args, const mp_o
} }
MP_DEFINE_CONST_FUN_OBJ_KW(digitalio_digitalinout_switch_to_input_obj, 1, digitalio_digitalinout_switch_to_input); MP_DEFINE_CONST_FUN_OBJ_KW(digitalio_digitalinout_switch_to_input_obj, 1, digitalio_digitalinout_switch_to_input);
//| direction: Any = ... //| direction: Direction = ...
//| """The direction of the pin. //| """The direction of the pin.
//| //|
//| Setting this will use the defaults from the corresponding //| Setting this will use the defaults from the corresponding
@ -220,7 +222,7 @@ const mp_obj_property_t digitalio_digitalio_direction_obj = {
(mp_obj_t)&mp_const_none_obj}, (mp_obj_t)&mp_const_none_obj},
}; };
//| value: Any = ... //| value: Bool = ...
//| """The digital logic level of the pin.""" //| """The digital logic level of the pin."""
//| //|
STATIC mp_obj_t digitalio_digitalinout_obj_get_value(mp_obj_t self_in) { STATIC mp_obj_t digitalio_digitalinout_obj_get_value(mp_obj_t self_in) {
@ -250,7 +252,7 @@ const mp_obj_property_t digitalio_digitalinout_value_obj = {
(mp_obj_t)&mp_const_none_obj}, (mp_obj_t)&mp_const_none_obj},
}; };
//| drive_mode: Any = ... //| drive_mode: DriveMode = ...
//| """The pin drive mode. One of: //| """The pin drive mode. One of:
//| //|
//| - `digitalio.DriveMode.PUSH_PULL` //| - `digitalio.DriveMode.PUSH_PULL`
@ -294,7 +296,7 @@ const mp_obj_property_t digitalio_digitalio_drive_mode_obj = {
(mp_obj_t)&mp_const_none_obj}, (mp_obj_t)&mp_const_none_obj},
}; };
//| pull: Any = ... //| pull: Optional[Pull] = ...
//| """The pin pull direction. One of: //| """The pin pull direction. One of:
//| //|
//| - `digitalio.Pull.UP` //| - `digitalio.Pull.UP`