CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2026-02-04
by AcustafQA

Original Post

Original - Posted on 2026-02-03
by Anerdw



            
Present in both answers; Present only in the new answer; Present only in the old answer;

You're missing an option which is type narrowing. Mypy as of 1.7 will recognize the tuple is proper if the length matches.
```python def shift_week(dayofweek: int, week: T_week) -> T_week: week_shifted: list[T_day] = [] week_shifted.extend(week[dayofweek:]) week_shifted.extend(week[:dayofweek]) rt = tuple(week_shifted) assert len(rt) == 7 return rt ```
Starting in version 1.7, mypy supports narrowing tuples using `len` checks. (This was part of [PR #16237].) Thus, you can just throw a quick assertion into your function:
```python T_day = int | None T_week = tuple[T_day, T_day, T_day, T_day, T_day, T_day, T_day]
def shift_week(dayofweek: int, week: T_week) -> T_week: week_shifted: list[T_day] = [] week_shifted.extend(week[dayofweek:]) week_shifted.extend(week[:dayofweek]) rt = tuple(week_shifted) assert len(rt) == 7 return rt ```
[PR #16237]: https://github.com/python/mypy/pull/16237

        
Present in both answers; Present only in the new answer; Present only in the old answer;