massucattoj commented on code in PR #41028: URL: https://github.com/apache/superset/pull/41028#discussion_r3607225557
########## superset/utils/number_format.py: ########## @@ -0,0 +1,333 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" +Server-side port of the d3-format based number and currency formatters used by +the Table and Pivot Table chart plugins. + +Report notifications that embed a chart as text build the table in Python and +have no access to the frontend formatters, so chart number/currency format +configuration has to be reproduced here to render the same values an end user +sees in the browser. + +Only d3-format specifiers (and the ``SMART_NUMBER`` pseudo-formats) are ported. +Non-d3 presets such as ``DURATION``, ``DURATION_SUB`` and the ``MEMORY_*`` +formatters are not supported: they do not parse as a d3 specifier and fall back +to the raw value, so a column using one of those renders unformatted in reports. +""" + +from __future__ import annotations + +import math +import re +from decimal import Decimal, ROUND_HALF_UP +from typing import Any + +from babel.numbers import get_currency_symbol + +SMART_NUMBER = "SMART_NUMBER" +SMART_NUMBER_SIGNED = "SMART_NUMBER_SIGNED" +AUTO_CURRENCY = "AUTO" + +LOCALE = "en_US" Review Comment: The repo's mypy config sets disallow_untyped_defs = false for tests, and the surrounding test files don't annotate test returns. Keeping consistent with that. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
