-
Notifications
You must be signed in to change notification settings - Fork 52
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
Unbound local x in percentage_to_str #250
Comments
#### Fixed: - Error when pasting into empty sheet - Potential error if using percentage formatter with more than just `int`, `float` and wrong type hint [250](#250) - Only show the selection box outline while the mouse is dragged if the control key is down - `index` and `header` `Span` parameters were not working with function `readonly()` #### Added: - Shift + arrowkey bindings for expanding/contracting a selection box - Functions for getting cell properties (options) [249](#249) - Ability to edit index in treeview mode, if the binding is enabled #### Improved: - Very slight performance boost to treeview insert, inserting rows when rows are hidden
Hello, Thanks for bringing this issue to my attention I had a look through the chain of functions and decided that there's not a guarantee that def percentage_to_str(v: object, **kwargs: dict) -> str:
if isinstance(v, (int, float)):
x = v * 100
if isinstance(x, float):
if x.is_integer():
return f"{int(x)}%"
if "decimals" in kwargs and isinstance(kwargs["decimals"], int):
if kwargs["decimals"]:
return f"{round(x, kwargs['decimals'])}%"
return f"{int(round(x, kwargs['decimals']))}%"
return f"{x}%"
return f"{v}%" |
lgtm. int will always be 0 or 100 (if math before calling this is correct) but I guess that's the only way to be consistent. |
By default the def my_new_func(s, **kws):
if s.endswith("%"):
return int(float(s.replace("%", "")) / 100)
return int(float(s))
sheet.format(
"A",
formatter_options=percentage_formatter(
format_function=my_new_func,
nullable=False,
),
) I have left it open to the possibility of the function receiving an There may also be the possibility of formatting using their own data types although you would assume if that were the case they would also provide their own to string function Finally, it's intentional that the default
I will make an alternative to the default keyword arguments which would make it as if the user had put a |
There is a question of what your intention was here. Reading the code seems to indicate that you meant to have this missing line:
def percentage_to_str(v: int | float, **kwargs: dict) -> str: + x = v
Did you plan to force an exception here if the type is wrong?
If so, this would be more clear:
I wasn't 100% sure otherwise I'd do a pull request (still can if you clarify).
The text was updated successfully, but these errors were encountered: