Options for shorthand for sys.platform checks #1953
-
This is related to a conversation on the use of Im looking for a way to use the about 12 additional sys.platform values that Micropython uses , without needing to write too long and repetitive boilerplate such as: if sys.platform == "esp32" or sys.platform == "esp8266" or sys.platform == "mimxrt" or sys.platform == "nrf" or sys.platform == "renesas-ra" or sys.platform == "rp2" or sys.platform == "samd" or sys.platform == "stm32" or sys.platform == "unix" or sys.platform == "webassembly" or sys.platform == "windows" or sys.platform == "zephyr" :
@overload
def sleep_ms(delay: float) -> None: ... Is there a way to shorten this ? for MicroPython there is a defined It would be possible to set sys.platform to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Currently, platform checks are underspecified in the typing spec: https://typing.python.org/en/latest/spec/directives.html#version-and-platform-checking From experience, currently only |
Beta Was this translation helpful? Give feedback.
-
I think it would be useful to specify If you're interested in pursuing this, I'd advise you to first start a thread on discuss.python.org, with the aim of brainstorming a concrete proposal. Then turn that into a PR to the typing spec, and follow the procedure in https://github.com/python/typing-council/#decisions to get the change into the spec. |
Beta Was this translation helpful? Give feedback.
I think it would be useful to specify
sys.platform
checks in more detail and add other useful patterns. For your example, it would be nice to supportif sys.platform in ('x', 'y'):
. Maybe there could also be a good way to support some version of "if on pypy", "if on cpython", "if on micropython".If you're interested in pursuing this, I'd advise you to first start a thread on discuss.python.org, with the aim of brainstorming a concrete proposal. Then turn that into a PR to the typing spec, and follow the procedure in https://github.com/python/typing-council/#decisions to get the change into the spec.