From 7093d37e781b812811fe8c82cd0bfc3cf04b2f62 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 4 Jan 2024 22:44:40 +0100 Subject: [PATCH] Fix flake8-bugbear warning B009 Do not call `getattr` with a constant attribute value. It is not any safer than normal property access. This was probably a hack to work around this MyPy error: error: Incompatible types in assignment (expression has type "Optional[str]", variable has type "str") [assignment] nstead, fix the error by using the proper type. --- src/packaging/_manylinux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/packaging/_manylinux.py b/src/packaging/_manylinux.py index 3705d50d..dfe65054 100644 --- a/src/packaging/_manylinux.py +++ b/src/packaging/_manylinux.py @@ -82,7 +82,7 @@ def _glibc_version_string_confstr() -> Optional[str]: # https://github.com/python/cpython/blob/fcf1d003bf4f0100c/Lib/platform.py#L175-L183 try: # Should be a string like "glibc 2.17". - version_string: str = getattr(os, "confstr")("CS_GNU_LIBC_VERSION") + version_string: Optional[int] = os.confstr("CS_GNU_LIBC_VERSION") assert version_string is not None _, version = version_string.rsplit() except (AssertionError, AttributeError, OSError, ValueError):