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

Code before:
    def __init__(self, entity_id: str):
        Reason.__init__(self, f"Entity {entity_id} is not a submittable entity")


class WrongConfigType(Reason):
    """
    WrongConfigType holds the reason the provided config is not the valid config expected.

    Attributes:
        config_id (str): The identifier of the config.
        config_type (str): The expected config type.
    """

    def __init__(self, config_id: str, config_type: Optional[str]):
        if config_type:
            reason = f'Object "{config_id}" must be a valid {config_type}'
        else:
            reason = f'Object "{config_id}" is not a valid config to be created'

        Reason.__init__(self, reason)


class NotGlobalScope(Reason):
    """
    NotGlobalScope holds the reason the data node config does not have a GLOBAL scope,
    which prevents certain actions from being performed.

    Attributes:
        config_id (str): The identifier of the config.
    """

    def __init__(self, config_id: str):
        Reason.__init__(self, f'Data node config "{config_id}" does not have GLOBAL scope')


Review comment (suggestion):
```suggestion
    A data node config does not have a GLOBAL scope, which prevents specific actions from being performed.
```

Code after:
    Attributes:
        entity_id (str): The identifier of the `Entity^`.
    """

    def __init__(self, entity_id: str):
        Reason.__init__(self, f"Entity {entity_id} is not a submittable entity")


class WrongConfigType(Reason):
    """
    A config id is not a valid expected config, which prevents specific actions from being performed.

    Attributes:
        config_id (str): The identifier of the config.
        config_type (str): The expected config type.
    """

    def __init__(self, config_id: str, config_type: Optional[str]):
        if config_type:
            reason = f'Object "{config_id}" must be a valid {config_type}'
        else:
            reason = f'Object "{config_id}" is not a valid config to be created'

        Reason.__init__(self, reason)


class NotGlobalScope(Reason):
    """
    A data node config does not have a GLOBAL scope, which prevents specific actions from being performed.

    Attributes:
        config_id (str): The identifier of the config.
    """

    def __init__(self, config_id: str):
        Reason.__init__(self, f'Data node config "{config_id}" does not have GLOBAL scope')
Repository: Avaiga/taipy
File: taipy/_cli/_create_cli.py (Python)

Code before:

    @classmethod
    def generate_template_map(cls, template_path: Optional[pathlib.Path] = None):
        if not template_path:
            template_path = pathlib.Path(taipy.__file__).parent.resolve() / "templates"

        # Update the template map with the new templates but do not override the existing ones
        cls._template_map.update(
            {
                str(x.name): str(x)
                for x in template_path.iterdir()
                if x.is_dir() and not x.name.startswith("_") and x.name not in cls._template_map
            }
        )

    @classmethod
    def create_parser(cls):
        create_parser = _TaipyParser._add_subparser(
            cls._COMMAND_NAME,
            help="Create a new Taipy application using pre-defined templates.",
        )
        create_parser.add_argument(
            "--application",
            choices=list(cls._template_map.keys()),
            default="default",
            help="The template name to create a new Taipy application.",
        )

    @classmethod
    def handle_command(cls):
        args = cls._parse_arguments()
        if not args:
            return
        try:
            cookiecutter(cls._template_map[args.application])
        except OutputDirExistsException as err:
            error_msg = f"{str(err)}. Please remove the existing directory or provide a new folder name."
            print(error_msg)  # noqa: T201
            sys.exit(1)
        sys.exit(0)


Review comment (suggestion):
```suggestion
            help="The template used to create the new Taipy application.",
```

Code after:

    @classmethod
    def generate_template_map(cls, template_path: Optional[pathlib.Path] = None):
        if not template_path:
            template_path = pathlib.Path(taipy.__file__).parent.resolve() / "templates"

        # Update the template map with the new templates but do not override the existing ones
        cls._template_map.update(
            {
                str(x.name): str(x)
                for x in template_path.iterdir()
                if x.is_dir() and not x.name.startswith("_") and x.name not in cls._template_map
            }
        )

    @classmethod
    def create_parser(cls):
        create_parser = _TaipyParser._add_subparser(
            cls._COMMAND_NAME,
            help="Create a new Taipy application using pre-defined templates.",
        )
        create_parser.add_argument(
            "--application",
            choices=list(cls._template_map.keys()),
            default="default",
            help="The template used to create the new Taipy application.",
        )

    @classmethod
    def handle_command(cls):
        args = cls._parse_arguments()
        if not args:
            return
        try:
            cookiecutter(cls._template_map[args.application])
        except OutputDirExistsException as err:
            error_msg = f"{str(err)}. Please remove the existing directory or provide a new folder name."
            print(error_msg)  # noqa: T201
            sys.exit(1)
        sys.exit(0)
Repository: Avaiga/taipy
File: taipy/core/reason/reason.py (Python)

Code before:
    def __init__(self, scenario_id: str):
        Reason.__init__(self, f"The scenario {scenario_id} does not belong to any cycle.")


class SubmissionIsNotFinished(Reason, _DataNodeReasonMixin):
    """
    The submission is not finished yet.

    Attributes:
        submission_id (str): The submission identifier.
    """

    def __init__(self, submission_id: str):
        Reason.__init__(self, f"The submission {submission_id} is not finished yet.")


class SubmissionStatusIsUndefined(Reason, _DataNodeReasonMixin):
    """
    The submission status is undefined.

    Attributes:
        submission_id (str): The submission identifier.
    """

    def __init__(self, submission_id: str):
        Reason.__init__(self, f"The submission {submission_id} status is undefined.")


Review comment (suggestion):
```suggestion
        Reason.__init__(self, f"The status of submission {submission_id} is undefined.")
```

Code after:
    def __init__(self, scenario_id: str):
        Reason.__init__(self, f"The scenario {scenario_id} does not belong to any cycle.")


class SubmissionIsNotFinished(Reason, _DataNodeReasonMixin):
    """
    The submission is not finished yet.

    Attributes:
        submission_id (str): The submission identifier.
    """

    def __init__(self, submission_id: str):
        Reason.__init__(self, f"The submission {submission_id} is not finished yet.")


class SubmissionStatusIsUndefined(Reason, _DataNodeReasonMixin):
    """
    The submission status is undefined.

    Attributes:
        submission_id (str): The submission identifier.
    """

    def __init__(self, submission_id: str):
        Reason.__init__(self, f"The status of submission {submission_id} is undefined.")
Repository: Avaiga/taipy
File: taipy/core/_core.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 taipy.logger._taipy_logger import _TaipyLogger

from .common._warnings import _warn_deprecated
from .orchestrator import Orchestrator


class Core:
    """Deprecated. Use `Orchestrator` class with `tp.Orchestrator()` instead."""

    __logger = _TaipyLogger._get_logger()

    def __new__(cls) -> Orchestrator:  # type: ignore
        _warn_deprecated("'Core'", suggest="the 'Orchestrator' class")
        cls.__logger.warning(
            "Class `Core` has been deprecated, an object of class `Orchestrator` will be created instead."
        )
        return Orchestrator()


Review comment (suggestion):
```suggestion
    """Deprecated. Use the `Orchestrator^` service class with `taipy.Orchestrator()` instead."""
```

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 taipy.logger._taipy_logger import _TaipyLogger

from .common._warnings import _warn_deprecated
from .orchestrator import Orchestrator


class Core:
    """Deprecated. Use the `Orchestrator^` service class with `taipy.Orchestrator()` instead."""

    __logger = _TaipyLogger._get_logger()

    def __new__(cls) -> Orchestrator:  # type: ignore
        _warn_deprecated("'Core'", suggest="the 'Orchestrator' class")
        cls.__logger.warning(
            "The `Core` service is deprecated and replaced by the `Orchestrator` service. "
            "An `Orchestrator` instance has been instantiated instead."
        )
        return Orchestrator()
Repository: Avaiga/taipy
File: taipy/core/_core.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 taipy.logger._taipy_logger import _TaipyLogger

from .common._warnings import _warn_deprecated
from .orchestrator import Orchestrator


class Core:
    """Deprecated. Use `Orchestrator` class with `tp.Orchestrator()` instead."""

    __logger = _TaipyLogger._get_logger()

    def __new__(cls) -> Orchestrator:  # type: ignore
        _warn_deprecated("'Core'", suggest="the 'Orchestrator' class")
        cls.__logger.warning(
            "Class `Core` has been deprecated, an object of class `Orchestrator` will be created instead."
        )
        return Orchestrator()


Review comment (suggestion):
```suggestion
            "The `Core` service is deprecated and replaced by the `Orchestrator` service. "
            "An `Orchestrator` instance has been instantiated instead."
```

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 taipy.logger._taipy_logger import _TaipyLogger

from .common._warnings import _warn_deprecated
from .orchestrator import Orchestrator


class Core:
    """Deprecated. Use the `Orchestrator^` service class with `taipy.Orchestrator()` instead."""

    __logger = _TaipyLogger._get_logger()

    def __new__(cls) -> Orchestrator:  # type: ignore
        _warn_deprecated("'Core'", suggest="the 'Orchestrator' class")
        cls.__logger.warning(
            "The `Core` service is deprecated and replaced by the `Orchestrator` service. "
            "An `Orchestrator` instance has been instantiated instead."
        )
        return Orchestrator()
Repository: Avaiga/taipy
File: taipy/config/exceptions/__init__.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.

"""# Exceptions raised by the config package."""
from .exceptions import *


Review comment (suggestion):
```suggestion
"""# Exceptions raised by the `taipy.config^` package."""
```

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.

"""# Exceptions raised by the `taipy.config^` package."""
from .exceptions import *
Repository: Avaiga/taipy
File: taipy/core/data/__init__.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.
"""Predefined Taipy data node implementations."""

from .aws_s3 import S3ObjectDataNode
from .csv import CSVDataNode
from .data_node import DataNode
from .excel import ExcelDataNode
from .generic import GenericDataNode
from .in_memory import InMemoryDataNode
from .json import JSONDataNode
from .mongo import MongoCollectionDataNode
from .operator import JoinOperator, Operator
from .parquet import ParquetDataNode
from .pickle import PickleDataNode
from .sql import SQLDataNode
from .sql_table import SQLTableDataNode


Review comment (suggestion):
And DataNode itself right?

```suggestion
"""Classes related to data nodes."""
```

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.
"""Classes related to data nodes."""

from .aws_s3 import S3ObjectDataNode
from .csv import CSVDataNode
from .data_node import DataNode
from .excel import ExcelDataNode
from .generic import GenericDataNode
from .in_memory import InMemoryDataNode
from .json import JSONDataNode
from .mongo import MongoCollectionDataNode
from .operator import JoinOperator, Operator
from .parquet import ParquetDataNode
from .pickle import PickleDataNode
from .sql import SQLDataNode
from .sql_table import SQLTableDataNode
Repository: Avaiga/taipy
File: taipy/rest/api/__init__.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.
""" Package for Taipy Rest API. """
from . import error_handler, views

__all__ = ["views", "error_handler"]


Review comment (suggestion):
```suggestion
"""Package for the Taipy Rest API."""
```

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.
"""Package for the Taipy Rest API."""
from . import error_handler, views

__all__ = ["views", "error_handler"]
Repository: Avaiga/taipy
File: taipy/core/job/_job_manager.py (Python)

Code before:

    @classmethod
    def _cancel(cls, job: Union[str, Job]) -> None:
        job = cls._get(job) if isinstance(job, str) else job

        from .._orchestrator._orchestrator_factory import _OrchestratorFactory

        _OrchestratorFactory._build_orchestrator().cancel_job(job)

    @classmethod
    def _get_latest(cls, task: Task) -> Optional[Job]:
        jobs_of_task = list(filter(lambda job: task in job, cls._get_all()))
        if len(jobs_of_task) == 0:
            return None
        if len(jobs_of_task) == 1:
            return jobs_of_task[0]
        else:
            return max(jobs_of_task)

    @classmethod
    def _is_deletable(cls, job: Union[Job, JobId]) -> ReasonCollection:
        reason_collector = ReasonCollection()

        if isinstance(job, str):
            job_id = job
            job = cls._get(job, None)
        else:
            job_id = job.id

        if job is None:
            reason_collector._add_reason(job_id, EntityDoesNotExist(job_id))
        elif not job.is_finished():
            reason_collector._add_reason(job.id, JobIsNotFinished(job.id))

        return reason_collector


Review comment (suggestion):
```suggestion
            if job:= cls._get(job, None) is None:
                reason_collector._add_reason(job_id, EntityDoesNotExist(job_id))
                return reason_collector
```

Code after:

    @classmethod
    def _cancel(cls, job: Union[str, Job]) -> None:
        job = cls._get(job) if isinstance(job, str) else job

        from .._orchestrator._orchestrator_factory import _OrchestratorFactory

        _OrchestratorFactory._build_orchestrator().cancel_job(job)

    @classmethod
    def _get_latest(cls, task: Task) -> Optional[Job]:
        jobs_of_task = list(filter(lambda job: task in job, cls._get_all()))
        if len(jobs_of_task) == 0:
            return None
        if len(jobs_of_task) == 1:
            return jobs_of_task[0]
        else:
            return max(jobs_of_task)

    @classmethod
    def _is_deletable(cls, job: Union[Job, JobId]) -> ReasonCollection:
        reason_collector = ReasonCollection()

        if isinstance(job, str):
            job_id = job
            job = cls._get(job, None)
            if job is None:
                reason_collector._add_reason(job_id, EntityDoesNotExist(job_id))
                return reason_collector

        if not job.is_finished():
            reason_collector._add_reason(job.id, JobIsNotFinished(job.id))

        return reason_collector
Repository: Avaiga/taipy
File: taipy/core/job/_job_manager.py (Python)

Code before:

        _OrchestratorFactory._build_orchestrator().cancel_job(job)

    @classmethod
    def _get_latest(cls, task: Task) -> Optional[Job]:
        jobs_of_task = list(filter(lambda job: task in job, cls._get_all()))
        if len(jobs_of_task) == 0:
            return None
        if len(jobs_of_task) == 1:
            return jobs_of_task[0]
        else:
            return max(jobs_of_task)

    @classmethod
    def _is_deletable(cls, job: Union[Job, JobId]) -> ReasonCollection:
        reason_collector = ReasonCollection()

        if isinstance(job, str):
            job_id = job
            job = cls._get(job, None)
        else:
            job_id = job.id

        if job is None:
            reason_collector._add_reason(job_id, EntityDoesNotExist(job_id))
        elif not job.is_finished():
            reason_collector._add_reason(job.id, JobIsNotFinished(job.id))

        return reason_collector


Review comment (suggestion):
From the previous comment, the case where the job can be None is already handled.
```suggestion
        if not job.is_finished():
```

Code after:

        _OrchestratorFactory._build_orchestrator().cancel_job(job)

    @classmethod
    def _get_latest(cls, task: Task) -> Optional[Job]:
        jobs_of_task = list(filter(lambda job: task in job, cls._get_all()))
        if len(jobs_of_task) == 0:
            return None
        if len(jobs_of_task) == 1:
            return jobs_of_task[0]
        else:
            return max(jobs_of_task)

    @classmethod
    def _is_deletable(cls, job: Union[Job, JobId]) -> ReasonCollection:
        reason_collector = ReasonCollection()

        if isinstance(job, str):
            job_id = job
            job = cls._get(job, None)
            if job is None:
                reason_collector._add_reason(job_id, EntityDoesNotExist(job_id))
                return reason_collector

        if not job.is_finished():
            reason_collector._add_reason(job.id, JobIsNotFinished(job.id))

        return reason_collector