On 16Jun2019 2354, Michael wrote:
CONCERN: How to organize platform dependent blocks of code
POLICY/RECOMMENDATION: (today) seems to be: arbitrary, although
sys.platform, seems to be the favorite.
* I, as 'python-consumer' was very surprised when I learned that
sys.platform is "set" when Python is built - and that platform.system()
was the call to make to get the run-time value. And, of course, they
answered the "question" - what platform am I 'running' on, quite
differently.
* There are several - to many - issues in the past where, in one form or
another, sys.platform, platform.system(), os.name, and I expect more but
cannot think of them atm - used throughout all of Python.
* A Python expert (e.g., core-devs) may understand - inherently - when
each of these is the best option.
As an 'experienced-novice' I am surprised that a "build-time constant"
seems to be preference. This preference is not new (maybe
platform.system() is "new", and os.name() too broad).
To help focus the discussion a bit, I recommend looking at what we've
already covered in https://bugs.python.org/issue36624
There really is an apparent lack of consistency in the test suite where
we use sys.platform, os.name and platform module checks to determine
whether a test should be run or not. This no doubt extends throughout
the standard library.
As Michael points out, sys.platform is a specific compile-time constant,
os.name is a vague compile-time constant, and the platform module
returns runtime values.
It's entirely possible that the mixed uses are correct, and that we are
correctly using sys.platform to test things that are based on
compile-time constants, correctly using os.name to choose between the
major flavors of posixmodule.c, and so on. But it's not obvious that we
are doing that, and it's not obvious what the correct choice should be
in any situation.
We could do with improving the guidance we provide in this area. And as
Michael says, we are the ones with the knowledge and ability to provide
that guidance. So this is really a call for opinions on "how should we
do platform-specific conditions".
Cheers,
Steve
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/TYARZX6XOFPAHEMUW3G5RUZACRLA64Z5/