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 Marcel Wilson



            
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 ```
Using [TypeGuard](https://typing.python.org/en/latest/spec/narrowing.html#typeguard) seems to be tailored for this kind of problem.

```python def has_7[T](tup: tuple[T, ...]) -> TypeGuard[tuple[T, T, T, T, T, T, T]]: return len(tup) == 7

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 has_7(rt) return rt ```

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