◐ Shell
clean mode source ↗

bpo-43312: Functions returning default and preferred sysconfig schemes by uranusjr · Pull Request #24644 · python/cpython

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main intention is to guard against incorrect implementation, since _get_preferred_schemes() is expected to be modified by redistributors and implementers. Say an implementer makes a typo:

def _get_preferred_schemes():
    return {
        "prefix": "posix_prefix",
        "home": "posix_home",
        "user": "posix_uesr",  # Oops!
    }

And when the value is later used:

scheme = sysconfig.get_preferred_scheme("user")

...  # Much later...

paths = sysconfig.get_paths(scheme)

This check would catch that posix_uesr is not actually a valid scheme and error early, instead of later when the user actually tries to use the (invalid) scheme.