Repository: Avaiga/taipy
File: taipy/core/taipy.py (Python)

Code before:
        return _SubmissionManagerFactory._build_manager()._hard_delete(SubmissionId(entity_id))
    raise ModelNotFound("NOT_DETERMINED", entity_id)


def get_scenarios(
    cycle: Optional[Cycle] = None,
    tag: Optional[str] = None,
    is_sorted: bool = False,
    descending: bool = False,
    sort_key: Literal["name", "id", "config_id", "creation_date", "tags"] = "name",
) -> List[Scenario]:
    """Retrieve a list of existing scenarios filtered by cycle or tag.

    This function allows you to retrieve a list of scenarios based on optional
    filtering criteria. If both a _cycle_ and a _tag_ are provided, the returned
    list contains scenarios that belong to the specified _cycle_ **and** also
    have the specified _tag_.

    Parameters:
         cycle (Optional[Cycle^]): The optional `Cycle^` to filter scenarios by.
         tag (Optional[str]): The optional tag to filter scenarios by.
         is_sorted (bool): The option to sort scenarios. The default sorting key is name.
         descending (bool): The option to sort scenarios on the sorting key in descending order.
         sort_key (Literal["name", "id", "creation_date", "tags"]): The optiononal sort_key to decide upon
             what key scenarios are sorted. The sorting is in increasing order for dates, in alphabetical order 
             for name and id, in lexographical order for tags.

    Returns:
        The list of scenarios filtered by cycle or tag and optionally sorted by name, id, creation_date or tags.
            If no filtering criterion is provided, this method returns all existing scenarios.
            If is_sorted is set to true, the scenarios are sorted by sort_key. The scenarios
            are sorted by name if an incorrect or no sort_key is provided.
    """
    scenario_manager = _ScenarioManagerFactory._build_manager()
    if not cycle and not tag:
        scenarios = scenario_manager._get_all()
    elif cycle and not tag:
        scenarios = scenario_manager._get_all_by_cycle(cycle)
    elif not cycle and tag:
        scenarios = scenario_manager._get_all_by_tag(tag)
    elif cycle and tag:
        cycles_scenarios = scenario_manager._get_all_by_cycle(cycle)
        scenarios = [scenario for scenario in cycles_scenarios if scenario.has_tag(tag)]
    else:
        scenarios = []

    if is_sorted:
        scenario_manager._sort_scenarios(scenarios, descending, sort_key)
    return scenarios



Review comment (suggestion):
W291 Trailing whitespace

```suggestion
         sort_key (Literal["name", "id", "creation_date", "tags"]): The optiononal sort_key to
             decide upon what key scenarios are sorted. The sorting is in increasing order for
             dates, in alphabetical order for name and id, in lexographical order for tags.
```

Code after:
    if _is_data_node(entity_id):
        return _DataManagerFactory._build_manager()._delete(DataNodeId(entity_id))
    if _is_submission(entity_id):
        return _SubmissionManagerFactory._build_manager()._hard_delete(SubmissionId(entity_id))
    raise ModelNotFound("NOT_DETERMINED", entity_id)


def get_scenarios(
    cycle: Optional[Cycle] = None,
    tag: Optional[str] = None,
    is_sorted: bool = False,
    descending: bool = False,
    sort_key: Literal["name", "id", "config_id", "creation_date", "tags"] = "name",
) -> List[Scenario]:
    """Retrieve a list of existing scenarios filtered by cycle or tag.

    This function allows you to retrieve a list of scenarios based on optional
    filtering criteria. If both a _cycle_ and a _tag_ are provided, the returned
    list contains scenarios that belong to the specified _cycle_ **and** also
    have the specified _tag_.

    Parameters:
         cycle (Optional[Cycle^]): The optional `Cycle^` to filter scenarios by.
         tag (Optional[str]): The optional tag to filter scenarios by.
         is_sorted (bool): The option to sort scenarios. The default sorting key is name.
         descending (bool): The option to sort scenarios on the sorting key in descending order.
         sort_key (Literal["name", "id", "creation_date", "tags"]): The optiononal sort_key to
             decide upon what key scenarios are sorted. The sorting is in increasing order for
             dates, in alphabetical order for name and id, in lexographical order for tags.

    Returns:
        The list of scenarios filtered by cycle or tag and optionally sorted by name, id, creation_date or tags.
            If no filtering criterion is provided, this method returns all existing scenarios.
            If is_sorted is set to true, the scenarios are sorted by sort_key. The scenarios
            are sorted by name if an incorrect or no sort_key is provided.
    """
    scenario_manager = _ScenarioManagerFactory._build_manager()
    if not cycle and not tag:
        scenarios = scenario_manager._get_all()
    elif cycle and not tag:
        scenarios = scenario_manager._get_all_by_cycle(cycle)
    elif not cycle and tag:
        scenarios = scenario_manager._get_all_by_tag(tag)
    elif cycle and tag:
        cycles_scenarios = scenario_manager._get_all_by_cycle(cycle)
        scenarios = [scenario for scenario in cycles_scenarios if scenario.has_tag(tag)]
    else:
        scenarios = []

    if is_sorted:
        scenario_manager._sort_scenarios(scenarios, descending, sort_key)