-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Improvement for Parser.addini to facilite parsing of 'int' and 'float' values #13193
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @harmin-parra for the PR!
Left some tweaks to the docs, otherwise LGTM!
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
There are still some mypy errors that I have no idea how to resolve |
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks!
I will leave it open for a few days to give others a chance to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all those casts in config/__init__.py
are incorrect and are hiding bugs.
A pyproject.toml with:
[tool.pytest.ini_options]
int_value = [3]
now causes
elif type == "int":
# value = cast(str, value)
try:
> return int(value)
^^^^^^^^^^
E TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
I suspect (but haven't tried) that passing an int/float for a paths
option will fail in a similar way.
We should probably do some additional validation that the input-type is correct, and raise an exception including the option name if not.
@The-Compiler I agree. Currently it is only catching |
That would still need a if not isinstance(value, (str, int)):
raise TypeError(f"Expected str or int for option {name} of type integer, but got: {value!r} ({type(value)})") or so would:
|
Sounds good. |
@The-Compiler applied the explicit checks. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small things about the type checks, other than that this seems good to go.
I think it would be good to have some tests for those error conditions because it took me a while to understand how those types could even get into the function (inicfg
didn't sound like it could be a typed TOML file). But if you feel like this is getting into too much of a tangent for this PR, I can understand.
Looking deeper I noticed that the previous annotations adding pytest/src/_pytest/config/findpaths.py Lines 85 to 91 in b28195f
|
Oh wow, good catch! I only tested with If they are indeed all strings, I believe those Though I wonder what happens with: elif type == "bool":
return _strtobool(str(value).strip())
elif type == "string":
return value if someone passes in a list value there? |
Ouch, of course, thanks for catching that. I fixed and improved he checks to at least provide a better message than the default (
pytest/src/_pytest/config/__init__.py Lines 1885 to 1900 in b302d31
But indeed |
@The-Compiler gentle ping. 👍 |
Co-authored-by: Florian Bruhin <me@the-compiler.org>
Implements #11381
parsing of
int
andfloat
configuration values from the ini files has been improved