ronantakizawa/codereview-bench huggingface dataset:
Repository: Avaiga/taipy
File: doc/gui/examples/controls/slider_labels_dictionary.py (Python)

Code before:
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed 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.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
#     python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

# Dictionary for slider labels
labels_with_dict = {
    0: "$0",
    1: "$1",
    2: "$2",
    3: "$3",
    4: "$4",
    5: "$5",
}

# Initial value of the slider
value = 0

# The slider uses the dictionary keys as a lov key or index, and the associated value as the label
page = """
Labels with Dictionary

<|{value}|slider|min=0|max=5|labels={labels_with_dict}|>

Value: <|{value}|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Slider - Labels with Dictionary")


Review comment (suggestion):
```suggestion
labels = {
    0: "One",
    1: "Two",
    2: "Three",
    3: "Four",
    4: "Five",
    5: "Six",
```

really showing the added value of key/value pairs.

Code after:
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed 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.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
#     python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

# Dictionary for slider labels
labels = {
    0: "$0",
    20: "$20",
    40: "$40",
    60: "$60",
    80: "$80",
    100: "$100",
}

# Initial value of the slider
value = 20

page = """
<|{value}|slider|labels={labels}|>

Value: <|${value}|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Slider - Labels with Dictionary")
Repository: Avaiga/taipy
File: doc/gui/examples/controls/slider_labels_dictionary.py (Python)

Code before:
# 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.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
#     python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

# Dictionary for slider labels
labels_with_dict = {
    0: "$0",
    1: "$1",
    2: "$2",
    3: "$3",
    4: "$4",
    5: "$5",
}

# Initial value of the slider
value = 0

# The slider uses the dictionary keys as a lov key or index, and the associated value as the label
page = """
Labels with Dictionary

<|{value}|slider|min=0|max=5|labels={labels_with_dict}|>

Value: <|{value}|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Slider - Labels with Dictionary")


Review comment (suggestion):
```suggestion
```
This line is useless: that would be the tab's title.

Code after:
# 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.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
#     python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

# Dictionary for slider labels
labels = {
    0: "$0",
    20: "$20",
    40: "$40",
    60: "$60",
    80: "$80",
    100: "$100",
}

# Initial value of the slider
value = 20

page = """
<|{value}|slider|labels={labels}|>

Value: <|${value}|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Slider - Labels with Dictionary")
Repository: Avaiga/taipy
File: doc/gui/examples/controls/slider_labels_dictionary.py (Python)

Code before:
# specific language governing permissions and limitations under the License.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
#     python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

# Dictionary for slider labels
labels_with_dict = {
    0: "$0",
    1: "$1",
    2: "$2",
    3: "$3",
    4: "$4",
    5: "$5",
}

# Initial value of the slider
value = 0

# The slider uses the dictionary keys as a lov key or index, and the associated value as the label
page = """
Labels with Dictionary

<|{value}|slider|min=0|max=5|labels={labels_with_dict}|>

Value: <|{value}|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Slider - Labels with Dictionary")


Review comment (suggestion):
```suggestion
<|{value}|slider|labels={labels}|>
```

Code after:
# specific language governing permissions and limitations under the License.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
#     python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

# Dictionary for slider labels
labels = {
    0: "$0",
    20: "$20",
    40: "$40",
    60: "$60",
    80: "$80",
    100: "$100",
}

# Initial value of the slider
value = 20

page = """
<|{value}|slider|labels={labels}|>

Value: <|${value}|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Slider - Labels with Dictionary")
Repository: Avaiga/taipy
File: tools/release/setup_version.py (Python)

Code before:
    name = f"{name}_VERSION" if name else "VERSION"
    print(f"{name}={version.name}")  # noqa: T201


if __name__ == "__main__":
    paths = (
        [sys.argv[1]]
        if sys.argv[1] != "ALL"
        else [
            f"taipy{os.sep}common",
            f"taipy{os.sep}core",
            f"taipy{os.sep}rest",
            f"taipy{os.sep}gui",
            f"taipy{os.sep}templates",
            "taipy",
        ]
    )
    _environment = sys.argv[2]

    for _path in paths:
        _version = extract_version(_path)
        _name = None if _path == "taipy" else _path.split(os.sep)[-1]

        if _environment == "dev":
            __setup_dev_version(_version, _path, _name)
            bump_ext_version(_version, _path)

        if _environment == "production":
            __setup_prod_version(_version, sys.argv[3], sys.argv[4], _name)


Review comment (suggestion):
It's not clear to me. Here is my understanding of the flow: 

- We dev release using the version in the version.json files.
- We bump up the version and write the version.json files
- We commit and push the changes

If this is correct, I don't get why you changed the version before releasing.




Code after:
    print(f"{name}={version.name}")  # noqa: T201


if __name__ == "__main__":
    paths = (
        [sys.argv[1]]
        if sys.argv[1] != "ALL"
        else [
            f"taipy{os.sep}common",
            f"taipy{os.sep}core",
            f"taipy{os.sep}rest",
            f"taipy{os.sep}gui",
            f"taipy{os.sep}templates",
            "taipy",
        ]
    )
    _environment = sys.argv[2]

    for _path in paths:
        _version = extract_version(_path)
        _name = None if _path == "taipy" else _path.split(os.sep)[-1]

        if _environment == "dev":
            __setup_dev_version(_version, _path, _name)

        if _environment == "production":
            __setup_prod_version(_version, sys.argv[3], sys.argv[4], _name)
Repository: Avaiga/taipy
File: doc/gui/extension/table_chess_game.py (Python)

Code before:
import pandas as pd
from example_library import ExampleLibrary

from taipy.gui import Gui

chessboard = [
    ["♖", "♘", "♗", "♕", "♔", "♗", "♘", "♖"],
    ["♙", "♙", "♙", "♙", "♙", "♙", "♙", "♙"],
    ["", "", "", "", "", "", "", ""],
    ["", "", "", "", "", "", "", ""],
    ["", "", "", "", "", "", "", ""],
    ["", "", "", "", "", "", "", ""],
    ["♟", "♟", "♟", "♟", "♟", "♟", "♟", "♟"],
    ["♜", "♞", "♝", "♛", "♚", "♝", "♞", "♜"]
]

# Create a DataFrame to represent the chessboard
data = pd.DataFrame(chessboard, columns=["A", "B", "C", "D", "E", "F", "G", "H"])

page = """
## Chess Game
<|{data}|example.game_table|>
"""

if __name__ == "__main__":
    Gui(page, libraries=[ExampleLibrary()]).run(title="Chess Game", port=3003)


Review comment (suggestion):
```suggestion
    Gui(page, libraries=[ExampleLibrary()]).run(title="Chess Game")
```

Code after:
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed 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.
from example_library import ExampleLibrary

from taipy.gui import Gui

data = [
    ["♖", "♘", "♗", "♕", "♔", "♗", "♘", "♖"],
    ["♙", "♙", "♙", "♙", "♙", "♙", "♙", "♙"],
    ["", "", "", "", "", "", "", ""],
    ["", "", "", "", "", "", "", ""],
    ["", "", "", "", "", "", "", ""],
    ["", "", "", "", "", "", "", ""],
    ["♟", "♟", "♟", "♟", "♟", "♟", "♟", "♟"],
    ["♜", "♞", "♝", "♛", "♚", "♝", "♞", "♜"]
]

page = """
## Chess Game
<|{data}|example.game_table|>
"""

if __name__ == "__main__":
    Gui(page, libraries=[ExampleLibrary()]).run(title="Chess Game")
Repository: Avaiga/taipy
File: doc/gui/extension/example_library/front-end/src/index.ts (TypeScript)

Code before:
// This file is the entry point of the JavaScript bundle loaded by the
// element library.
//
// All the React components that are used by elements should be imported,
// indicating their source file name, then exported.
//
// Note that we export the 'ColoredLabel' component as 'ExampleLabel', which is
// the name used in the element declaration in the element library.
import ColoredLabel from "./ColoredLabel";
import GameTable from "./BasicTable";

export { ColoredLabel as ExampleLabel, GameTable };


Review comment (suggestion):
```suggestion
import GameTable from "./GameTable";
```

Code after:
// This file is the entry point of the JavaScript bundle loaded by the
// element library.
//
// All the React components that are used by elements should be imported,
// indicating their source file name, then exported.
//
// Note that we export the 'ColoredLabel' component as 'ExampleLabel', which is
// the name used in the element declaration in the element library.
import ColoredLabel from "./ColoredLabel";
import GameTable from "./GameTable";

export { ColoredLabel as ExampleLabel, GameTable };
Repository: Avaiga/taipy
File: doc/gui/examples/controls/chat-streaming.py (Python)

Code before:
            state_id,
            set_message,
            [f"requesting Wikipedia failed: {req.status_code}", idx],
        )


# invoked by the on_action on the chat control when the user press the send button
def send_message(state: State, id: str, payload: dict):
    args = payload.get("args", [])

    # display request
    state.messages.append((f"{len(state.messages)}", args[2], args[3]))
    state.refresh("messages")

    # analyse request
    request = args[2].lower()
    type_event = None
    for word in event_types:
        if word in request:
            type_event = event_types[word]
            break
    type_event = type_event if type_event else "events"

    month = None
    day = None
    for m in re.finditer(r"(\d\d?)", request):
        if month is None:
            month = m.group()
        elif day is None:
            day = m.group()
            break
    if month is None:
        month = f"{datetime.datetime.now().month}"
    if day is None:
        day = f"{datetime.datetime.now().day}"

    # process request
    invoke_long_callback(
        state=state,
        user_function=request_wikipedia,
        user_function_args=[state.get_gui(), get_state_id(state), type_event, month, day],
    )


page = """
<|{messages}|chat|users={users}|on_action=send_message|height=80vh|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Chat- Streaming Wikipedia")


Review comment (suggestion):
```suggestion
    for m in re.finditer(r"(\d+)", request):
```
Shorted and less constrained... may be not what you really want.

Code after:
            state_id,
            set_message,
            [f"Wikipedia API call failed: {req.status_code}", idx],
        )


# Invoked by the 'on_action' callback of the chat control when the user presses the Send button
def send_message(state: State, id: str, payload: dict):
    args = payload.get("args", [])

    # Display the request
    state.messages.append((f"{len(state.messages)}", args[2], args[3]))
    state.refresh("messages")

    # Analyse the request
    request = args[2].lower()
    type_event = None
    for word in event_types:
        if word in request:
            type_event = event_types[word]
            break
    type_event = type_event if type_event else "events"

    month = None
    day = None
    for m in re.finditer(r"(\d\d?)", request):
        if month is None:
            month = m.group()
        elif day is None:
            day = m.group()
            break
    if month is None:
        month = f"{datetime.datetime.now().month}"
    if day is None:
        day = f"{datetime.datetime.now().day}"

    # Process the request
    invoke_long_callback(
        state=state,
        user_function=request_wikipedia,
        user_function_args=[state.get_gui(), get_state_id(state), type_event, month, day],
    )


page = """
<|{messages}|chat|users={users}|on_action=send_message|height=80vh|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Chat - Ask Wikipedia")
Repository: Avaiga/taipy
File: doc/gui/examples/controls/chat-streaming.py (Python)

Code before:
    day = None
    for m in re.finditer(r"(\d\d?)", request):
        if month is None:
            month = m.group()
        elif day is None:
            day = m.group()
            break
    if month is None:
        month = f"{datetime.datetime.now().month}"
    if day is None:
        day = f"{datetime.datetime.now().day}"

    # process request
    invoke_long_callback(
        state=state,
        user_function=request_wikipedia,
        user_function_args=[state.get_gui(), get_state_id(state), type_event, month, day],
    )


page = """
<|{messages}|chat|users={users}|on_action=send_message|height=80vh|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Chat- Streaming Wikipedia")


Review comment (suggestion):
```suggestion
    Gui(page).run(title="Chat - Ask Wikipedia")
```

Code after:
    day = None
    for m in re.finditer(r"(\d\d?)", request):
        if month is None:
            month = m.group()
        elif day is None:
            day = m.group()
            break
    if month is None:
        month = f"{datetime.datetime.now().month}"
    if day is None:
        day = f"{datetime.datetime.now().day}"

    # Process the request
    invoke_long_callback(
        state=state,
        user_function=request_wikipedia,
        user_function_args=[state.get_gui(), get_state_id(state), type_event, month, day],
    )


page = """
<|{messages}|chat|users={users}|on_action=send_message|height=80vh|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Chat - Ask Wikipedia")
Repository: Avaiga/taipy
File: doc/gui/examples/blocks/layout_fit/markdown.py (Python)

Code before:
# 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.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
#     python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

page = """
<|layout|columns=max-content max-content|

<|card|part|
Metric 1
|>

<|card|part|
Metric 2
|>

|>
"""

if __name__ == "__main__":
    Gui(page).run(title="layout - fit content")


Review comment (suggestion):
```suggestion
    Gui(page).run(title="Layout - Fit to content")
```

Code after:
# 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.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
#     python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

page = """
<|layout|columns=max-content max-content|

<|card|part|
France
|>

<|card|part|
United States of America
|>

|>
"""

if __name__ == "__main__":
    Gui(page).run(title="Layout - Fit to content")
Repository: Avaiga/taipy
File: doc/gui/examples/blocks/layout_fit/builder.py (Python)

Code before:
#
# Licensed 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.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
#     python <script>
# -----------------------------------------------------------------------------------------
import taipy.gui.builder as tgb
from taipy.gui import Gui

with tgb.Page() as page:
    with tgb.layout("max-content max-content"):  # type: ignore[attr-defined]
        with tgb.part("card"):  # type: ignore[attr-defined]
            tgb.text("Metric 1")  # type: ignore[attr-defined]
        with tgb.part("card"):  # type: ignore[attr-defined]
            tgb.text("Metric 2")  # type: ignore[attr-defined]

if __name__ == "__main__":
    Gui(page).run(title="layout - fit content")


Review comment (suggestion):
```suggestion
    Gui(page).run(title="Layout - Fit to content")
```

Code after:
#
# Licensed 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.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
#     python <script>
# -----------------------------------------------------------------------------------------
import taipy.gui.builder as tgb
from taipy.gui import Gui

with tgb.Page() as page:
    with tgb.layout("max-content max-content"):  # type: ignore[attr-defined]
        with tgb.part("card"):  # type: ignore[attr-defined]
            tgb.text("France")  # type: ignore[attr-defined]
        with tgb.part("card"):  # type: ignore[attr-defined]
            tgb.text("United States of America")  # type: ignore[attr-defined]

if __name__ == "__main__":
    Gui(page).run(title="Layout - Fit to content")