-
-
Notifications
You must be signed in to change notification settings - Fork 365
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
Python 3.10 deprecation in tests due to distutils #813
Comments
I‘d add this as def to_bool(val: Any) -> bool:
"""
Convert "boolean" strings (e.g., from env. vars.) to real booleans.
Values mapping to :code:`True`:
- :code:`True`
- :code:`"true"` / :code:`"t"`
- :code:`"yes"` / :code:`"y"`
- :code:`"on"`
- :code:`"1"`
- :code:`1`
Values mapping to :code:`False`:
- :code:`False`
- :code:`"false"` / :code:`"f"`
- :code:`"no"` / :code:`"n"`
- :code:`"off"`
- :code:`"0"`
- :code:`0`
Raise :exc:`ValueError` for any other value.
"""
if isinstance(val, str):
val = val.lower()
truthy = {True, "true", "t", "yes", "y", "on", "1", 1}
falsy = {False, "false", "f", "no", "n", "off", "0", 0}
try:
if val in truthy:
return True
if val in falsy:
return False
except TypeError:
# Raised when "val" is not hashable (e.g., lists)
pass
raise ValueError(f"Cannot convert value to bool: {val}") to This function is already part of typed-settings and I intended to eventually move it to attrs. @hynek, what do you think? |
SGTM but remember to put the annotations into the stub file. :) |
sscherfke
added a commit
that referenced
this issue
Jun 5, 2021
10 tasks
sscherfke
added a commit
that referenced
this issue
Jun 6, 2021
9999years
pushed a commit
to 9999years/attrs
that referenced
this issue
Jul 7, 2021
`distutils` is deprecated in Python 3.10 and slated for removal in Python 3.12. Fortunately, `attrs` only uses `distutils` once and it's trivial to remove. As suggested by @sscherfke, add the `to_bool` converter to `converters.py`. Closes python-attrs#813 Co-authored-by: Stefan Scherfke <stefan@sofa-rockers.org>
10 tasks
9999years
pushed a commit
to 9999years/attrs
that referenced
this issue
Jul 7, 2021
`distutils` is deprecated in Python 3.10 and slated for removal in Python 3.12. Fortunately, `attrs` only uses `distutils` once and it's trivial to remove. As suggested by @sscherfke, add the `to_bool` converter to `converters.py`. Closes python-attrs#813 Co-authored-by: Stefan Scherfke <stefan@sofa-rockers.org>
hynek
added a commit
that referenced
this issue
Aug 10, 2021
* Inline distutils.util.strtobool in tests (#813) `distutils` is deprecated in Python 3.10 and slated for removal in Python 3.12. Fortunately, `attrs` only uses `distutils` once and it's trivial to remove. As suggested by @sscherfke, add the `to_bool` converter to `converters.py`. Closes #813 Co-authored-by: Stefan Scherfke <stefan@sofa-rockers.org> * Use :raises: directive in docstring * Remove f-strings for Py2.7 and 3.5 support * Add to_bool tests Co-authored-by: Stefan Scherfke <stefan@sofa-rockers.org> Co-authored-by: Hynek Schlawack <hs@ox.cx>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The function is simple enough to be vendored for tests.
attrs/tests/test_converters.py
Line 7 in d0cff8f
The text was updated successfully, but these errors were encountered: