Fix platform-dependent type-check errors (#11345)
Use more explicit `sys.platform` checks, instead of the previous check using `in`, which mypy understands. Fixes #11343
This commit is contained in:
parent
00fedcc439
commit
ff23347f1f
|
@ -314,15 +314,24 @@ 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 process's real user id or None if it could not be
|
||||||
|
determined.
|
||||||
|
|
||||||
|
:return: The user id or None if it could not be determined.
|
||||||
|
"""
|
||||||
|
# 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.
|
||||||
|
if sys.platform == "win32" or sys.platform == "emscripten":
|
||||||
# win32 does not have a getuid() function.
|
# win32 does not have a getuid() function.
|
||||||
# On Emscripten, getuid() is a stub that always returns 0.
|
# Emscripten has a return 0 stub.
|
||||||
if sys.platform in ("win32", "emscripten"):
|
|
||||||
return None
|
return None
|
||||||
# getuid shouldn't fail, but cpython defines such a case.
|
else:
|
||||||
# Let's hope for the best.
|
# On other platforms, a return value of -1 is assumed to indicate that
|
||||||
|
# the current process's real user id could not be determined.
|
||||||
|
ERROR = -1
|
||||||
uid = os.getuid()
|
uid = os.getuid()
|
||||||
return uid if uid != -1 else None
|
return uid if uid != ERROR else None
|
||||||
|
|
||||||
|
|
||||||
# Perform exhaustiveness checking.
|
# Perform exhaustiveness checking.
|
||||||
|
|
|
@ -291,7 +291,8 @@ class TestParser:
|
||||||
|
|
||||||
def test_argcomplete(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
|
def test_argcomplete(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
|
||||||
try:
|
try:
|
||||||
encoding = locale.getencoding() # New in Python 3.11, ignores utf-8 mode
|
# New in Python 3.11, ignores utf-8 mode
|
||||||
|
encoding = locale.getencoding() # type: ignore[attr-defined]
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
encoding = locale.getpreferredencoding(False)
|
encoding = locale.getpreferredencoding(False)
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue