ronantakizawa/codereview-bench huggingface dataset:
Repository: Avaiga/taipy
File: taipy/core/config/scenario_config.py (Python)

Code before:
                if not has_input and not has_output:
                    g.add_node(task)
            return g
        graph = build_dag()
        dag = _DAG(graph)
        pos = {node.entity: (node.x, node.y) for node in dag.nodes.values()}
        labls = {node.entity: node.entity.id for node in dag.nodes.values()}

        # Draw the graph
        plt.figure(figsize=(10, 10))
        nx.draw_networkx_nodes(graph, pos,
                               nodelist=[node for node in graph.nodes if isinstance(node, DataNodeConfig)],
                               node_color="skyblue",
                               node_shape="s",
                               node_size=2000)
        nx.draw_networkx_nodes(graph, pos,
                               nodelist=[node for node in graph.nodes if isinstance(node, TaskConfig)],
                               node_color="orange",
                               node_shape="D",
                               node_size=2000)
        nx.draw_networkx_labels(graph, pos, labels=labls)
        nx.draw_networkx_edges(graph, pos, node_size=2000, edge_color="black", arrowstyle="->", arrowsize=25)
        path = file_path or f"{self.id}.png"
        plt.savefig(path)
        plt.close()  # Close the plot to avoid display
        logger.info(f"Graph exported as image: {path}")


Review comment (suggestion):
```suggestion
        logger.info(f"The graph image of the scenario configuration `{self.id}` is exported: {path}")
```

Code after:
                if not has_input and not has_output:
                    g.add_node(task)
            return g
        graph = build_dag()
        dag = _DAG(graph)
        pos = {node.entity: (node.x, node.y) for node in dag.nodes.values()}
        labls = {node.entity: node.entity.id for node in dag.nodes.values()}

        # Draw the graph
        plt.figure(figsize=(10, 10))
        nx.draw_networkx_nodes(graph, pos,
                               nodelist=[node for node in graph.nodes if isinstance(node, DataNodeConfig)],
                               node_color="skyblue",
                               node_shape="s",
                               node_size=2000)
        nx.draw_networkx_nodes(graph, pos,
                               nodelist=[node for node in graph.nodes if isinstance(node, TaskConfig)],
                               node_color="orange",
                               node_shape="D",
                               node_size=2000)
        nx.draw_networkx_labels(graph, pos, labels=labls)
        nx.draw_networkx_edges(graph, pos, node_size=2000, edge_color="black", arrowstyle="->", arrowsize=25)
        path = file_path or f"{self.id}.png"
        plt.savefig(path)
        plt.close()  # Close the plot to avoid display
        logger.info(f"The graph image of the scenario configuration `{self.id}` is exported: {path}")
Repository: Avaiga/taipy
File: tests/gui/e2e/test_resizing.py (Python)

Code before:
import inspect
from importlib import util

import pandas
import pytest

if util.find_spec("playwright"):
    from playwright._impl._page import Page

from taipy.gui import Gui


@pytest.mark.teste2e
def test_has_default_value(page: Page, gui: Gui, helpers):
    percentages = [
        (1852, 50.83),
        (1856, 45.29),
        (1860, 39.65),
        (1864, 55.03),
    ]
    data = pandas.DataFrame(percentages, columns=["Year", "%"]) # noqa: F841
    page_md = """
<|{data}|chart|type=bar|x=Year|y=%|>
"""
    gui._set_frame(inspect.currentframe())
    gui.add_page(name="test",page=page_md)
    helpers.run_e2e(gui)
    page.goto("./test")
    page.wait_for_timeout(3000)
    page.wait_for_selector(".plot-container")
    page.set_viewport_size({"width": 800, "height": 600})
    elements = page.locator(
        'path[style*="vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(99, 110, 250); fill-opacity: 1;"]') # noqa: E501
    first_element = elements.first
    box_before = first_element.bounding_box()
    page.set_viewport_size({"width": 1920, "height": 1080})
    page.wait_for_timeout(1000)
    box_after = first_element.bounding_box()
    assert box_after['width'] > box_before['width']


Review comment (suggestion):
```suggestion
    page_md = "<|{data}|chart|type=bar|x=Year|y=%|>"
```

Code after:
import inspect
from importlib import util

import pandas
import pytest

if util.find_spec("playwright"):
    from playwright._impl._page import Page

from taipy.gui import Gui


@pytest.mark.teste2e
def test_has_default_value(page: Page, gui: Gui, helpers):
    percentages = [
        (1852, 50.83),
        (1856, 45.29),
        (1860, 39.65),
        (1864, 55.03),
    ]
    data = pandas.DataFrame(percentages, columns=["Year", "%"]) # noqa: F841
    page_md = "<|{data}|chart|type=bar|x=Year|y=%|>"
    gui._set_frame(inspect.currentframe())
    gui.add_page(name="test",page=page_md)
    helpers.run_e2e(gui)
    page.goto("./test")
    page.wait_for_timeout(3000)
    page.wait_for_selector(".plot-container")
    page.set_viewport_size({"width": 800, "height": 600})
    elements = page.locator(
        'path[style*="vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(99, 110, 250); fill-opacity: 1;"]') # noqa: E501
    first_element = elements.first
    box_before = first_element.bounding_box()
    page.set_viewport_size({"width": 1920, "height": 1080})
    page.wait_for_timeout(1000)
    box_after = first_element.bounding_box()
    assert box_after["width"] > box_before["width"]
Repository: Avaiga/taipy
File: tests/gui/e2e/test_resizing.py (Python)

Code before:
def test_has_default_value(page: Page, gui: Gui, helpers):
    percentages = [
        (1852, 50.83),
        (1856, 45.29),
        (1860, 39.65),
        (1864, 55.03),
    ]
    data = pandas.DataFrame(percentages, columns=["Year", "%"]) # noqa: F841
    page_md = """
<|{data}|chart|type=bar|x=Year|y=%|>
"""
    gui._set_frame(inspect.currentframe())
    gui.add_page(name="test",page=page_md)
    helpers.run_e2e(gui)
    page.goto("./test")
    page.wait_for_timeout(3000)
    page.wait_for_selector(".plot-container")
    page.set_viewport_size({"width": 800, "height": 600})
    elements = page.locator(
        'path[style*="vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(99, 110, 250); fill-opacity: 1;"]') # noqa: E501
    first_element = elements.first
    box_before = first_element.bounding_box()
    page.set_viewport_size({"width": 1920, "height": 1080})
    page.wait_for_timeout(1000)
    box_after = first_element.bounding_box()
    assert box_after['width'] > box_before['width']


Review comment (suggestion):
```suggestion
    assert box_after["width"] > box_before["width"]
```

Code after:
import inspect
from importlib import util

import pandas
import pytest

if util.find_spec("playwright"):
    from playwright._impl._page import Page

from taipy.gui import Gui


@pytest.mark.teste2e
def test_has_default_value(page: Page, gui: Gui, helpers):
    percentages = [
        (1852, 50.83),
        (1856, 45.29),
        (1860, 39.65),
        (1864, 55.03),
    ]
    data = pandas.DataFrame(percentages, columns=["Year", "%"]) # noqa: F841
    page_md = "<|{data}|chart|type=bar|x=Year|y=%|>"
    gui._set_frame(inspect.currentframe())
    gui.add_page(name="test",page=page_md)
    helpers.run_e2e(gui)
    page.goto("./test")
    page.wait_for_timeout(3000)
    page.wait_for_selector(".plot-container")
    page.set_viewport_size({"width": 800, "height": 600})
    elements = page.locator(
        'path[style*="vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(99, 110, 250); fill-opacity: 1;"]') # noqa: E501
    first_element = elements.first
    box_before = first_element.bounding_box()
    page.set_viewport_size({"width": 1920, "height": 1080})
    page.wait_for_timeout(1000)
    box_after = first_element.bounding_box()
    assert box_after["width"] > box_before["width"]
Repository: Avaiga/taipy
File: taipy/core/notification/core_event_consumer.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.
from queue import SimpleQueue

from ...common.logger._taipy_logger import _TaipyLogger
from ..common._warnings import _warn_deprecated
from ._core_event_consumer import _CoreEventConsumerBase


class CoreEventConsumerBase(_CoreEventConsumerBase):
    """NOT DOCUMENTED"""

    __logger = _TaipyLogger._get_logger()

    def __init__(self, registration_id: str, queue: SimpleQueue) -> None:
        _warn_deprecated(deprecated="CoreEventConsumerBase",
                         suggest="The 'taipy.event.event_consumer.GuiEventConsumer' class")
        self.__logger.warning(
            "The `CoreEventConsumerBase` class is deprecated since taipy 4.1.0."
            "Please use the `GuiEventConsumer` class instead. "
        )
        super().__init__(registration_id, queue)


Review comment (bug):
Let me know if I'm wrong. I think we need a space here

```suggestion
            "The `CoreEventConsumerBase` class is deprecated since taipy 4.1.0. "
            "Please use the `GuiEventConsumer` class instead."
```

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.
from queue import SimpleQueue

from ...common.logger._taipy_logger import _TaipyLogger
from ..common._warnings import _warn_deprecated
from ._core_event_consumer import _CoreEventConsumerBase


class CoreEventConsumerBase(_CoreEventConsumerBase):
    """NOT DOCUMENTED"""

    __logger = _TaipyLogger._get_logger()

    def __init__(self, registration_id: str, queue: SimpleQueue) -> None:
        _warn_deprecated(deprecated="CoreEventConsumerBase",
                         suggest="The 'taipy.event.event_consumer.GuiEventConsumer' class")
        self.__logger.warning(
            "The `CoreEventConsumerBase` class is deprecated since taipy 4.1.0. "
            "Please use the `GuiEventConsumer` class instead."
        )
        super().__init__(registration_id, queue)
Repository: Avaiga/taipy
File: taipy/core/notification/core_event_consumer.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.
from queue import SimpleQueue

from ...common.logger._taipy_logger import _TaipyLogger
from ..common._warnings import _warn_deprecated
from ._core_event_consumer import _CoreEventConsumerBase


class CoreEventConsumerBase(_CoreEventConsumerBase):
    """NOT DOCUMENTED"""

    __logger = _TaipyLogger._get_logger()

    def __init__(self, registration_id: str, queue: SimpleQueue) -> None:
        _warn_deprecated(deprecated="CoreEventConsumerBase",
                         suggest="The 'taipy.event.event_consumer.GuiEventConsumer' class")
        self.__logger.warning(

Review comment (suggestion):
```suggestion
# Copyright 2021-2025 Avaiga Private Limited
```

Code after:
# Copyright 2021-2025 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 queue import SimpleQueue

from ...common.logger._taipy_logger import _TaipyLogger
from ..common._warnings import _warn_deprecated
from ._core_event_consumer import _CoreEventConsumerBase


class CoreEventConsumerBase(_CoreEventConsumerBase):
    """NOT DOCUMENTED"""

    __logger = _TaipyLogger._get_logger()

    def __init__(self, registration_id: str, queue: SimpleQueue) -> None:
        _warn_deprecated(deprecated="CoreEventConsumerBase",
                         suggest="The 'taipy.event.event_consumer.GuiEventConsumer' class")
        self.__logger.warning(
Repository: Avaiga/taipy
File: taipy/core/notification/core_event_consumer.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.
from queue import SimpleQueue

from ...common.logger._taipy_logger import _TaipyLogger
from ..common._warnings import _warn_deprecated
from ._core_event_consumer import _CoreEventConsumerBase


class CoreEventConsumerBase(_CoreEventConsumerBase):
    """NOT DOCUMENTED"""

    __logger = _TaipyLogger._get_logger()

    def __init__(self, registration_id: str, queue: SimpleQueue) -> None:
        _warn_deprecated(deprecated="CoreEventConsumerBase",
                         suggest="The 'taipy.event.event_consumer.GuiEventConsumer' class")
        self.__logger.warning(
            "The `CoreEventConsumerBase` class is deprecated since taipy 4.1.0."
            "Please use the `GuiEventConsumer` class instead. "
        )
        super().__init__(registration_id, queue)


Review comment (suggestion):
```suggestion
            "The `CoreEventConsumerBase` class is deprecated since taipy 4.1.0. "
            "Please use the `GuiEventConsumer` class instead."
```

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.
from queue import SimpleQueue

from ...common.logger._taipy_logger import _TaipyLogger
from ..common._warnings import _warn_deprecated
from ._core_event_consumer import _CoreEventConsumerBase


class CoreEventConsumerBase(_CoreEventConsumerBase):
    """NOT DOCUMENTED"""

    __logger = _TaipyLogger._get_logger()

    def __init__(self, registration_id: str, queue: SimpleQueue) -> None:
        _warn_deprecated(deprecated="CoreEventConsumerBase",
                         suggest="The 'taipy.event.event_consumer.GuiEventConsumer' class")
        self.__logger.warning(
            "The `CoreEventConsumerBase` class is deprecated since taipy 4.1.0. "
            "Please use the `GuiEventConsumer` class instead."
        )
        super().__init__(registration_id, queue)
Repository: AvaloniaUI/Avalonia
File: src/Avalonia.Controls/Window.cs (C#)

Code before:
                if (ignoreCancel || !cancelClosing)
                {
                    s_windows.Remove(this);
                    PlatformImpl?.Dispose();
                    IsVisible = false;
                }
            }
        }

        /// <summary>
        /// Handles a closing notification from <see cref="IWindowImpl.Closing"/>.
        /// </summary>
        protected virtual bool HandleClosing()
        {
            var args = new CancelEventArgs();
            Closing?.Invoke(this, args);
            return args.Cancel;
        }

        protected virtual void HandleWindowStateChanged(WindowState state)
        {
            if (state == WindowState.Minimized)
            {
                Renderer.Stop();
            }
            else if (state == WindowState.Normal)
            {
                Renderer.Start();
            }
        }

        /// <summary>
        /// Hides the window but does not close it.
        /// </summary>
        public override void Hide()
        {
            if (!IsVisible)
            {
                return;
            }

            using (BeginAutoSizing())
            {
                Renderer?.Stop();
                PlatformImpl?.Hide();
            }

            IsVisible = false;
        }

        /// <summary>

Review comment (suggestion):
This should probably just
```
else
{
    Renderer.Start();
}
```


Code after:
            var cancelClosing = false;
            try
            {
                cancelClosing = HandleClosing();
            }
            finally
            {
                if (ignoreCancel || !cancelClosing)
                {
                    s_windows.Remove(this);
                    PlatformImpl?.Dispose();
                    IsVisible = false;
                }
            }
        }

        /// <summary>
        /// Handles a closing notification from <see cref="IWindowImpl.Closing"/>.
        /// </summary>
        protected virtual bool HandleClosing()
        {
            var args = new CancelEventArgs();
            Closing?.Invoke(this, args);
            return args.Cancel;
        }

        protected virtual void HandleWindowStateChanged(WindowState state)
        {
            WindowState = state;

            if (state == WindowState.Minimized)
            {
                Renderer.Stop();
            }
            else
            {
                Renderer.Start();
            }
        }

        /// <summary>
        /// Hides the window but does not close it.
        /// </summary>
        public override void Hide()
        {
            if (!IsVisible)
            {
                return;
            }

            using (BeginAutoSizing())
Repository: AvaloniaUI/Avalonia
File: src/Avalonia.Visuals/Media/FormattedText.cs (C#)

Code before:
        /// <summary>
        /// Gets the bounds rectangle that the specified character occupies.
        /// </summary>
        /// <param name="index">The index of the character.</param>
        /// <returns>The character bounds.</returns>
        public Rect HitTestTextPosition(int index)
        {
            return PlatformImpl.HitTestTextPosition(index);
        }

        /// <summary>
        /// Gets the bounds rectangles that the specified text range occupies.
        /// </summary>
        /// <param name="index">The index of the first character.</param>
        /// <param name="length">The number of characters in the text range.</param>
        /// <returns>The character bounds.</returns>
        public IEnumerable<Rect> HitTestTextRange(int index, int length)
        {
            return PlatformImpl.HitTestTextRange(index, length);
        }

        /// <summary>
        /// Gets the bounds of the text, taking <see cref="Constraint"/> into account.
        /// </summary>
        /// <returns>The bounds of the text.</returns>
        public Rect Measure() => PlatformImpl.Bounds;

        private void Set<T>(ref T field, T value)
        {
            field = value;
            _platformImpl = null;
        }
    }
}


Review comment (suggestion):
We will never calculate anything here. Text layouts are immutable. The moment we construct one measures are fixed. I suggest changing this to a property `public Rect Bounds { get; }` or just use `PlatformImpl.Bounds`

Code after:
        /// </returns>
        public TextHitTestResult HitTestPoint(Point point)
        {
            return PlatformImpl.HitTestPoint(point);
        }

        /// <summary>
        /// Gets the bounds rectangle that the specified character occupies.
        /// </summary>
        /// <param name="index">The index of the character.</param>
        /// <returns>The character bounds.</returns>
        public Rect HitTestTextPosition(int index)
        {
            return PlatformImpl.HitTestTextPosition(index);
        }

        /// <summary>
        /// Gets the bounds rectangles that the specified text range occupies.
        /// </summary>
        /// <param name="index">The index of the first character.</param>
        /// <param name="length">The number of characters in the text range.</param>
        /// <returns>The character bounds.</returns>
        public IEnumerable<Rect> HitTestTextRange(int index, int length)
        {
            return PlatformImpl.HitTestTextRange(index, length);
        }

        private void Set<T>(ref T field, T value)
        {
            field = value;
            _platformImpl = null;
        }
    }
}