Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use strict optional checking in glibc #12091

Merged
merged 7 commits into from
Jul 5, 2023

Conversation

hauntsaninja
Copy link
Contributor

@hauntsaninja hauntsaninja commented Jun 20, 2023

Suggested by pradyunsg in #11374

--no-strict-optional defeats half the purpose of using mypy.

This change is trivial, just need a type ignore since we already catch AttributeError in the case that mypy is concerned about.

Suggested by pradyunsg in pypa#11374

`--no-strict-optional` defeats half the purpose of using mypy.

This change is trivial, we already catch AttributeError in the case that
mypy is concerned about.
@@ -21,7 +18,7 @@ def glibc_version_string_confstr() -> Optional[str]:
return None
try:
# os.confstr("CS_GNU_LIBC_VERSION") returns a string like "glibc 2.17":
_, version = os.confstr("CS_GNU_LIBC_VERSION").split()
_, version = os.confstr("CS_GNU_LIBC_VERSION").split() # type: ignore[union-attr]
Copy link
Member

@uranusjr uranusjr Jun 20, 2023

Choose a reason for hiding this comment

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

What is this ignoring? If it’s the None case, we should explicitly check for that instead

glibc_version = os.confstr("CS_GNU_LIBC_VERSION")
if glibc_version is None:
    return None
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's ignoring the case where it returns None, because we already catch an AttributeError one line below

From https://docs.python.org/3/library/os.html#os.confstr

If the configuration value specified by name isn’t defined, None is returned

Copy link
Contributor Author

@hauntsaninja hauntsaninja Jun 20, 2023

Choose a reason for hiding this comment

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

I can change so we don't catch AttributeError though, just costs a line or two

edit: we still need to catch AttributeError because os.confstr is only available on Unix

Copy link
Member

Choose a reason for hiding this comment

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

Theoratically Windows shouldn’t reach this line at all since there’s a check above (which is why Mypy does not complain). But it’s probably still best to keep the AttributeError just in case.

@uranusjr uranusjr merged commit 4734c4c into pypa:main Jul 5, 2023
@hauntsaninja hauntsaninja deleted the strict-optional-glibc branch July 5, 2023 16:10
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants