refactor: replace type:ignore with platform check
This commit is contained in:
parent
2a91c63318
commit
15ebcf55d1
|
@ -314,15 +314,20 @@ def safe_isclass(obj: object) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def get_user_id() -> int | None:
|
def get_user_id() -> int | None:
|
||||||
"""Return the current user id, or None if we cannot get it reliably on the current platform."""
|
"""Return the current user id, or None if we cannot get it reliably on
|
||||||
# win32 does not have a getuid() function.
|
the current platform."""
|
||||||
# On Emscripten, getuid() is a stub that always returns 0.
|
# mypy follows the version and platform checking expectation of PEP 484:
|
||||||
if sys.platform in ("win32", "emscripten"):
|
# 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.
|
||||||
|
if sys.platform == "win32" or sys.platform == "emscripten":
|
||||||
|
# win32 does not have a getuid() function.
|
||||||
|
# Emscripten has a return 0 stub.
|
||||||
return None
|
return None
|
||||||
# getuid shouldn't fail, but cpython defines such a case.
|
# getuid shouldn't fail but cpython defines such a case.
|
||||||
# Let's hope for the best.
|
# Let's hope for the best.
|
||||||
uid = os.getuid() # type: ignore[attr-defined]
|
else:
|
||||||
return uid if uid != -1 else None
|
uid = os.getuid()
|
||||||
|
return uid if uid != -1 else None
|
||||||
|
|
||||||
|
|
||||||
# Perform exhaustiveness checking.
|
# Perform exhaustiveness checking.
|
||||||
|
|
Loading…
Reference in New Issue