-
Notifications
You must be signed in to change notification settings - Fork 55
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
improve and move isfloat(num) #127
Conversation
function is not used here
improved isfloat for case "None" and strings with surrounding whitespace and special types like +-inf.
@@ -26,6 +27,25 @@ | |||
) | |||
|
|||
|
|||
def isfloat(num: Any) -> bool: |
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.
you could add a TypeGuard:
from typing import TypeGuard
def isfloat(num: Any) -> TypeGuard[float]
if you test if isfloat(my_var)
my_var will be recognized as float by the linter.
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.
oh that's a very nice function I did not know about.
According to PEP 647 thats in Version 3.10 introduced. Currently we need 3.8+ according to the readme. Would 3.10+ be a problem? Ill add it
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 did not check the required python version, my bad.
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.
do you see any reason not to change the python version needed? 3.10 is already 4 years old.
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.
personally I would even go to 11 or even 13. But as the program is also distributed as a package that other people can implement, it is better to support more versions.
@NormannK None is not accepted by JSON. |
I guess I'm the only one besides you running that code actively. In my backend I save everything into a table and go from there. Also I simply ignore the first value. But i see what you are referring too. So we don't have proper type sanitation before translating it into json. |
Pydantic is also a good option to parse data from and to json. The bonus point: you have a nice object that carries your data so you can access it via attributes which increases type safety. I used it in my suggestion for the config. @drbacke regarding the config, can you give me a feedback why you closed the PR? |
meeeeh, ok. I'll reopen with the new branch. |
fixing #126 by adding case "None", stings with whitespace and special types like +-inf.
Also moving the function to the server since its only used there.