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

Code before:
        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


def get_primary(cycle: Cycle) -> Optional[Scenario]:
    """Retrieve the primary scenario associated with a cycle.

    Parameters:
        cycle (Cycle^): The cycle for which to retrieve the primary scenario.

    Returns:
        The primary scenario of the given _cycle_. If the cycle has no
            primary scenario, this method returns None.
    """
    return _ScenarioManagerFactory._build_manager()._get_primary(cycle)


def get_primary_scenarios(
    is_sorted: Optional[bool] = False,
    descending: Optional[bool] = False,
    sort_key: Optional[Literal["name", "id", "config_id", "creation_date", "tags"]] = "name",
) -> List[Scenario]:
    """Retrieve a list of all primary scenarios.

    Parameters:
         is_sorted (Optional[bool]): The option to sort scenarios. The default sorting key is name.
         descending (Optional[bool]): The option to sort scenarios on the sorting key in descending order.
         sort_key (Optional[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 containing all primary scenarios, optionally sorted by name, id, creation_date or tags.
            The sorting is in increasing order for dates, in alphabetical order for name and 
            id, and in lexicographical order for tags. If sorted is set to true, but if an
            incorrect or no sort_key is provided, the scenarios are sorted by name.
    """
    scenario_manager = _ScenarioManagerFactory._build_manager()
    scenarios = scenario_manager._get_primary_scenarios()
    if is_sorted:
        scenario_manager._sort_scenarios(scenarios, descending, sort_key)
    return scenarios



def is_promotable(scenario: Union[Scenario, ScenarioId]) -> bool:

Review comment (suggestion):
```suggestion
    is_sorted: bool = False,
    descending: bool = False,
    sort_key: Literal["name", "id", "config_id", "creation_date", "tags"] = "name",
```

Code after:
        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


def get_primary(cycle: Cycle) -> Optional[Scenario]:
    """Retrieve the primary scenario associated with a cycle.

    Parameters:
        cycle (Cycle^): The cycle for which to retrieve the primary scenario.

    Returns:
        The primary scenario of the given _cycle_. If the cycle has no
            primary scenario, this method returns None.
    """
    return _ScenarioManagerFactory._build_manager()._get_primary(cycle)


def get_primary_scenarios(
    is_sorted: bool = False,
    descending: bool = False,
    sort_key: Literal["name", "id", "config_id", "creation_date", "tags"] = "name",
) -> List[Scenario]:
    """Retrieve a list of all primary scenarios.

    Parameters:
         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 containing all primary scenarios, optionally sorted by name, id, creation_date or tags.
            The sorting is in increasing order for dates, in alphabetical order for name and
            id, and in lexicographical order for tags. If sorted is set to true, but if an
            incorrect or no sort_key is provided, the scenarios are sorted by name.
    """
    scenario_manager = _ScenarioManagerFactory._build_manager()
    scenarios = scenario_manager._get_primary_scenarios()
    if is_sorted:
        scenario_manager._sort_scenarios(scenarios, descending, sort_key)
    return scenarios