refactor: add self-documenting UNRELIABLE keyword
This commit is contained in:
parent
fe67feb4d3
commit
2d5bfa8dab
|
@ -313,9 +313,16 @@ def safe_isclass(obj: object) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def get_user_id() -> int | None:
|
||||
def get_user_id(*, UNRELIABLE: int = -1) -> int | None:
|
||||
"""Return the current user id, or None if we cannot get it reliably on
|
||||
the current platform."""
|
||||
the current platform.
|
||||
|
||||
:param UNRELIABLE:
|
||||
The platform-specific constant which indicates that the retrieved uid
|
||||
is unreliable. The default value, -1, is a common unreliability
|
||||
indicator on UNIX-like systems.
|
||||
:return: The user id or None
|
||||
"""
|
||||
# mypy follows the version and platform checking expectation of PEP 484:
|
||||
# https://mypy.readthedocs.io/en/stable/common_issues.html?highlight=platform#python-version-and-system-platform-checks
|
||||
# Containment checks are too complex for mypy v1.5.0 and cause failure.
|
||||
|
@ -323,11 +330,9 @@ def get_user_id() -> int | None:
|
|||
# win32 does not have a getuid() function.
|
||||
# Emscripten has a return 0 stub.
|
||||
return None
|
||||
# getuid shouldn't fail but cpython defines such a case.
|
||||
# Let's hope for the best.
|
||||
else:
|
||||
uid = os.getuid()
|
||||
return uid if uid != -1 else None
|
||||
return uid if uid != UNRELIABLE else None
|
||||
|
||||
|
||||
# Perform exhaustiveness checking.
|
||||
|
|
Loading…
Reference in New Issue