ronantakizawa/codereview-bench huggingface dataset:
Repository: youzan/vant
File: packages/vant/src/date-picker/DatePicker.tsx (TypeScript)

Code before:
        minMonth,
        maxMonth,
        'month',
        props.formatter,
        props.filter,
      );
    };

    const genDayOptions = () => {
      const year = getValue('year');
      const month = getValue('month');
      const minDate =
        isMinYear(year) && isMinMonth(month) ? props.minDate.getDate() : 1;
      const maxDate =
        isMaxYear(year) && isMaxMonth(month)
          ? props.maxDate.getDate()
          : getMonthEndDay(year, month);

      return genOptions(minDate, maxDate, 'day', props.formatter, props.filter);
    };

    const confirm = () => {
      return pickerRef.value?.confirm();
    };

    const getSelectedDate = (): Array<string> => {
      return currentValues.value;
    };

    const columns = computed(() =>
      props.columnsType.map((type) => {
        switch (type) {
          case 'year':
            return genYearOptions();
          case 'month':
            return genMonthOptions();
          case 'day':
            return genDayOptions();
          default:
            if (process.env.NODE_ENV !== 'production') {
              throw new Error(
                `[Vant] DatePicker: unsupported columns type: ${type}`,
              );
            }
            return [];
        }
      }),
    );

    watch(currentValues, (newValues) => {
      if (!isSameValue(newValues, props.modelValue)) {

Review comment (suggestion):
```suggestion
    const getSelectedDate = () => {
```

Code after:
        minMonth,
        maxMonth,
        'month',
        props.formatter,
        props.filter,
      );
    };

    const genDayOptions = () => {
      const year = getValue('year');
      const month = getValue('month');
      const minDate =
        isMinYear(year) && isMinMonth(month) ? props.minDate.getDate() : 1;
      const maxDate =
        isMaxYear(year) && isMaxMonth(month)
          ? props.maxDate.getDate()
          : getMonthEndDay(year, month);

      return genOptions(minDate, maxDate, 'day', props.formatter, props.filter);
    };

    const confirm = () => {
      return pickerRef.value?.confirm();
    };

    const getSelectedDate = () => {
      return currentValues.value;
    };

    const columns = computed(() =>
      props.columnsType.map((type) => {
        switch (type) {
          case 'year':
            return genYearOptions();
          case 'month':
            return genMonthOptions();
          case 'day':
            return genDayOptions();
          default:
            if (process.env.NODE_ENV !== 'production') {
              throw new Error(
                `[Vant] DatePicker: unsupported columns type: ${type}`,
              );
            }
            return [];
        }
      }),
    );

    watch(currentValues, (newValues) => {
      if (!isSameValue(newValues, props.modelValue)) {
Repository: youzan/vant
File: packages/vant/src/date-picker/DatePicker.tsx (TypeScript)

Code before:
import {
  ref,
  watch,
  computed,
  defineComponent,
  ComponentPublicInstance,
  type PropType,
  type ExtractPropTypes,
} from 'vue';

// Utils
import { pick, extend, isDate, isSameValue, createNamespace } from '../utils';
import {
  genOptions,
  sharedProps,
  getMonthEndDay,
  pickerInheritKeys,
  formatValueRange,
} from './utils';

// Components
import { Picker, PickerInstance } from '../picker';
import { useExpose } from '../composables/use-expose';

const currentYear = new Date().getFullYear();
const [name] = createNamespace('date-picker');

export type DatePickerColumnType = 'year' | 'month' | 'day';

export const datePickerProps = extend({}, sharedProps, {
  columnsType: {

Review comment (suggestion):
```suggestion
  type ComponentPublicInstance,
```

Code after:
import {
  ref,
  watch,
  computed,
  defineComponent,
  type ComponentPublicInstance,
  type PropType,
  type ExtractPropTypes,
} from 'vue';

// Utils
import { pick, extend, isDate, isSameValue, createNamespace } from '../utils';
import {
  genOptions,
  sharedProps,
  getMonthEndDay,
  pickerInheritKeys,
  formatValueRange,
} from './utils';

// Components
import { Picker, PickerInstance } from '../picker';
import { useExpose } from '../composables/use-expose';

const currentYear = new Date().getFullYear();
const [name] = createNamespace('date-picker');

export type DatePickerColumnType = 'year' | 'month' | 'day';

export const datePickerProps = extend({}, sharedProps, {
  columnsType: {
Repository: youzan/vant
File: packages/vant/src/area/test/index.spec.ts (TypeScript)

Code before:
import { Area } from '..';
import { areaList } from '../demo/area-simple';
import { mount, later, triggerDrag } from '../../../test';
import {
  PickerCancelEventParams,
  PickerChangeEventParams,
  PickerConfirmEventParams,
} from '../../picker';

test('should columns placeholder displayed normally', async () => {
  const columnsPlaceholder = ['省份', '省份', '区县'];

  const wrapper = mount(Area, {
    props: {
      areaList,
      columnsPlaceholder,
    },
  });

  const columns = await wrapper.findAll('.van-picker-column');
  await columns[0].findAll('li')?.[1].trigger('click');
  expect(columns[1].find('li').text()).toBe(columnsPlaceholder[1]);

  await columns[1].findAll('li')?.[1].trigger('click');
  expect(columns[2].find('li').text()).toBe(columnsPlaceholder[2]);
});

test('should emit confirm event after click the confirm button', async () => {
  const wrapper = mount(Area, {
    props: {
      areaList,
    },
  });

  await wrapper.find('.van-picker__confirm').trigger('click');
  const params = wrapper.emitted<PickerConfirmEventParams[]>('confirm')?.[0];

Review comment (suggestion):
Prefer using English in test files:

```suggestion
  const columnsPlaceholder = ['Province', 'City', 'County'];
```

Code after:
import { Area } from '..';
import { areaList } from '../demo/area-simple';
import { mount, later, triggerDrag } from '../../../test';
import {
  PickerCancelEventParams,
  PickerChangeEventParams,
  PickerConfirmEventParams,
} from '../../picker';

test('should columns placeholder displayed normally', async () => {
  const columnsPlaceholder = ['Province', 'City', 'County'];

  const wrapper = mount(Area, {
    props: {
      areaList,
      columnsPlaceholder,
    },
  });

  const columns = await wrapper.findAll('.van-picker-column');
  await columns[0].findAll('li')?.[1].trigger('click');
  expect(columns[1].find('li').text()).toBe(columnsPlaceholder[1]);

  await columns[1].findAll('li')?.[1].trigger('click');
  expect(columns[2].find('li').text()).toBe(columnsPlaceholder[2]);
});

test('should emit confirm event after click the confirm button', async () => {
  const wrapper = mount(Area, {
    props: {
      areaList,
    },
  });

  await wrapper.find('.van-picker__confirm').trigger('click');
  const params = wrapper.emitted<PickerConfirmEventParams[]>('confirm')?.[0];
Repository: youzan/vant
File: packages/vant/src/calendar/Calendar.tsx (TypeScript)

Code before:
    ) => {
      if (min && compareDay(date, min) === -1) {
        return min;
      }
      if (max && compareDay(date, max) === 1) {
        return max;
      }
      return date;
    };

    const getInitialDate = (defaultDate = props.defaultDate) => {
      const { type, allowSameDay } = props;

      if (defaultDate === null) {
        return defaultDate;
      }

      const now = getToday();

      if (type === 'range') {
        if (!Array.isArray(defaultDate)) {
          defaultDate = [];
        }

        if (defaultDate.length === 1 && compareDay(defaultDate[0], now) === 1) {
          defaultDate = [];
        }

        const min = minDate.value;
        const max = maxDate.value;

        const start = limitDateRange(
          defaultDate[0] || now,
          min,
          max ? (allowSameDay ? max : getPrevDay(max)) : undefined,
        );

        const end = limitDateRange(
          defaultDate[1] || (allowSameDay ? now : getNextDay(now)),
          min ? (allowSameDay ? min : getNextDay(min)) : undefined,
        );

        return [start, end];
      }

      if (type === 'multiple') {
        if (Array.isArray(defaultDate)) {
          return defaultDate.map((date) => limitDateRange(date));
        }
        return [limitDateRange(now)];
      }

Review comment (suggestion):
```suggestion
        // reset invalid default date
        if (defaultDate.length === 1 && compareDay(defaultDate[0], now) === 1) {
```

Code after:
    ) => {
      if (min && compareDay(date, min) === -1) {
        return min;
      }
      if (max && compareDay(date, max) === 1) {
        return max;
      }
      return date;
    };

    const getInitialDate = (defaultDate = props.defaultDate) => {
      const { type, allowSameDay } = props;

      if (defaultDate === null) {
        return defaultDate;
      }

      const now = getToday();

      if (type === 'range') {
        if (!Array.isArray(defaultDate)) {
          defaultDate = [];
        }

        // reset invalid default date
        if (defaultDate.length === 1 && compareDay(defaultDate[0], now) === 1) {
          defaultDate = [];
        }

        const min = minDate.value;
        const max = maxDate.value;

        const start = limitDateRange(
          defaultDate[0] || now,
          min,
          max ? (allowSameDay ? max : getPrevDay(max)) : undefined,
        );

        const end = limitDateRange(
          defaultDate[1] || (allowSameDay ? now : getNextDay(now)),
          min ? (allowSameDay ? min : getNextDay(min)) : undefined,
        );

        return [start, end];
      }

      if (type === 'multiple') {
        if (Array.isArray(defaultDate)) {
          return defaultDate.map((date) => limitDateRange(date));
        }
        return [limitDateRange(now)];
Repository: youzan/vant
File: packages/vant/src/calendar/CalendarDay.tsx (TypeScript)

Code before:
          <div class={bem('top-info')}>
            {slots['top-info'] ? slots['top-info'](props.item) : topInfo}
          </div>
        );
      }
    };

    const renderBottomInfo = () => {
      const { bottomInfo } = props.item;

      if (bottomInfo || slots['bottom-info']) {
        return (
          <div class={bem('bottom-info')}>
            {slots['bottom-info']
              ? slots['bottom-info'](props.item)
              : bottomInfo}
          </div>
        );
      }
    };

    const renderText = () => {
      const { item } = props;
      const { text } = item;

      return <>{slots.text ? slots.text(props.item) : text}</>;
    };

    const renderContent = () => {
      const { item, color, rowHeight } = props;
      const { type } = item;

      const Nodes = [renderTopInfo(), renderText(), renderBottomInfo()];

      if (type === 'selected') {
        return (
          <div
            class={bem('selected-day')}
            style={{
              width: rowHeight,
              height: rowHeight,
              background: color,
            }}
          >
            {Nodes}
          </div>
        );
      }

      return Nodes;
    };

Review comment (suggestion):
```suggestion
      return slots.text ? slots.text(props.item) : props.item.text;
```

Code after:
          <div class={bem('top-info')}>
            {slots['top-info'] ? slots['top-info'](props.item) : topInfo}
          </div>
        );
      }
    };

    const renderBottomInfo = () => {
      const { bottomInfo } = props.item;

      if (bottomInfo || slots['bottom-info']) {
        return (
          <div class={bem('bottom-info')}>
            {slots['bottom-info']
              ? slots['bottom-info'](props.item)
              : bottomInfo}
          </div>
        );
      }
    };

    const renderText = () => {
      return slots.text ? slots.text(props.item) : props.item.text;
    };

    const renderContent = () => {
      const { item, color, rowHeight } = props;
      const { type } = item;

      const Nodes = [renderTopInfo(), renderText(), renderBottomInfo()];

      if (type === 'selected') {
        return (
          <div
            class={bem('selected-day')}
            style={{
              width: rowHeight,
              height: rowHeight,
              background: color,
            }}
          >
            {Nodes}
          </div>
        );
      }

      return Nodes;
    };

    return () => {
      const { type, className } = props.item;
Repository: youzan/vant
File: packages/vant/src/picker/test/index.spec.tsx (TypeScript)

Code before:
    ],
    Shanghai: [
      { text: 'Huangpu', value: 'Huangpu' },
      { text: 'Xuhui', value: 'Xuhui' },
      { text: 'Changning', value: 'Changning' },
      { text: 'Pudong', value: 'Pudong' },
    ],
  };
  const currentValues = ref(['Beijing', 'Dongcheng']);
  const wrapper = mount({
    setup() {
      const columns = computed(() => [
        columnsOne,
        columnsTwo[currentValues.value[0]],
      ]);
      return () => (
        <Picker v-model={currentValues.value} columns={columns.value} />
      );
    },
  });
  const picker = wrapper.findComponent(Picker);
  // Scroll to select "Shanghai"
  triggerDrag(picker.findAll('.van-picker-column')[0], 0, -100);
  // Trigger confirm immediately without waiting for scroll animation to complete
  // ⚠️ DO NOT uncomment, this line is for documentation purposes only
  // await picker.find('.van-picker-column ul').trigger('transitionend');
  await picker.find('.van-picker__confirm').trigger('click');
  expect(picker.emitted('confirm')![0]).toEqual([
    {
      selectedOptions: [
        { text: 'Shanghai', value: 'Shanghai' },
        { text: 'Huangpu', value: 'Huangpu' },
      ],
      selectedValues: ['Shanghai', 'Huangpu'],
      selectedIndexes: [1, 0],
    },
  ]);
});


Review comment (suggestion):
```suggestion
```
Since the comment in the previous line is very clear, we can remove the comment here.

Code after:
    ],
    Shanghai: [
      { text: 'Huangpu', value: 'Huangpu' },
      { text: 'Xuhui', value: 'Xuhui' },
      { text: 'Changning', value: 'Changning' },
      { text: 'Pudong', value: 'Pudong' },
    ],
  };
  const currentValues = ref(['Beijing', 'Dongcheng']);
  const wrapper = mount({
    setup() {
      const columns = computed(() => [
        columnsOne,
        columnsTwo[currentValues.value[0]],
      ]);
      return () => (
        <Picker v-model={currentValues.value} columns={columns.value} />
      );
    },
  });
  const picker = wrapper.findComponent(Picker);
  // Scroll to select "Shanghai"
  triggerDrag(picker.findAll('.van-picker-column')[0], 0, -100);
  // Trigger confirm immediately without waiting for scroll animation to complete
  await picker.find('.van-picker__confirm').trigger('click');
  expect(picker.emitted('confirm')![0]).toEqual([
    {
      selectedOptions: [
        { text: 'Shanghai', value: 'Shanghai' },
        { text: 'Huangpu', value: 'Huangpu' },
      ],
      selectedValues: ['Shanghai', 'Huangpu'],
      selectedIndexes: [1, 0],
    },
  ]);
});
Repository: yt-dlp/yt-dlp
File: youtube_dlc/extractor/zee5.py (Python)

Code before:
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor

import requests

token_url = "https://useraction.zee5.com/tokennd"
search_api_endpoint = "https://gwapi.zee5.com/content/details/"
platform_token = "https://useraction.zee5.com/token/platform_tokens.php?platform_name=web_app"
stream_baseurl = "https://zee5vodnd.akamaized.net"

headers = {
    "User-Agent": "Mozilla/5.0 (Linux; Android 10; SM-J400F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Mobile Safari/537.36",
    "Referer": "https://www.zee5.com",
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "en-US,en;q=0.9",
    "Origin": "https://www.zee5.com",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
}


class Zee5IE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?zee5\.com/.*/(?P<id>.*)'
    _TEST = {
        'url': 'https://www.zee5.com/movies/details/krishna-the-birth/0-0-63098',
        # 'md5': 'cd5abd10fab020dbb633cb8e94df0e12',
        'info_dict': {

Review comment (suggestion):
Dont use `requests`, use `self._download_json` to download the json

Code after:
# coding: utf-8
from __future__ import unicode_literals

import re

from .common import InfoExtractor
from ..utils import (
    int_or_none,
    parse_age_limit,
    str_or_none,
    try_get,
    unified_strdate,
    unified_timestamp,
    url_or_none,
)


class Zee5IE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?zee5\.com/[^#?]*/(?P<display_id>[-\w]+)/(?P<id>[-\d]+)'
    _TESTS = [{
        'url': 'https://www.zee5.com/movies/details/krishna-the-birth/0-0-63098',
        'info_dict': {
            "id": "0-0-63098",
            "ext": "m3u8",
            "display_id": "krishna-the-birth",
            "title": "Krishna - The Birth",
            "duration": 4368,
            "average_rating": 4,
            "description": str,
            "alt_title": "Krishna - The Birth",
            "uploader": "Zee Entertainment Enterprises Ltd",
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/amcnetworks.py (Python)

Code before:
                continue
            i = {'url': thumbnail_url}
            mobj = re.search(r'(\d+)x(\d+)', thumbnail_url)
            if mobj:
                i.update({
                    'width': int(mobj.group(1)),
                    'height': int(mobj.group(2)),
                })
            thumbnails.append(i)
        # Sometimes these thumbnails are the same image despite having
        # different URLs.  Sometimes they're entirely different images,
        # not just different resolutions of one image.

        info.update({
            'id': video_id,
            'subtitles': subtitles,
            'formats': formats,
            'age_limit': parse_age_limit(parse_age_limit(rating)),
            'thumbnails': thumbnails,
        })
        ns_keys = theplatform_metadata.get('$xmlns', {}).keys()
        if ns_keys:
            ns = list(ns_keys)[0]
            series = theplatform_metadata.get(ns + '$show')
            if not series:
                series = None  # Convert empty string to None
            season_number = int_or_none(
                theplatform_metadata.get(ns + '$season'))
            episode = theplatform_metadata.get(ns + '$episodeTitle')
            if not episode:
                episode = None
            episode_number = int_or_none(
                theplatform_metadata.get(ns + '$episode'))
            info.update({
                'series': series,
                'season_number': season_number,
                'episode': episode,
                'episode_number': episode_number,
            })
        return info


Review comment (suggestion):
```suggestion
            series = theplatform_metadata.get(ns + '$show') or None
```

Code after:
                'width': int(mobj.group(1)) if mobj else None,
                'height': int(mobj.group(2)) if mobj else None,
            })

        info.update({
            'age_limit': parse_age_limit(rating),
            'formats': formats,
            'id': video_id,
            'subtitles': subtitles,
            'thumbnails': thumbnails,
        })
        ns_keys = theplatform_metadata.get('$xmlns', {}).keys()
        if ns_keys:
            ns = list(ns_keys)[0]
            episode = theplatform_metadata.get(ns + '$episodeTitle') or None
            episode_number = int_or_none(
                theplatform_metadata.get(ns + '$episode'))
            season_number = int_or_none(
                theplatform_metadata.get(ns + '$season'))
            series = theplatform_metadata.get(ns + '$show') or None
            info.update({
                'episode': episode,
                'episode_number': episode_number,
                'season_number': season_number,
                'series': series,
            })
        return info
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/la7.py (Python)

Code before:
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        return self._extract_infos(webpage, video_id)


class LA7PodcastIE(LA7PodcastEpisodeIE):
    IE_NAME = 'la7.it:podcast'
    _VALID_URL = r'(https?://)?(www\.)?la7\.it/(?P<id>[^/]+)/podcast$'''

    _TESTS = [{
        'url': 'https://www.la7.it/propagandalive/podcast',
        'info_dict': {
            'id': 'propagandalive',
            'title': "Propaganda Live",
        },
        'playlist_count': 10,
    }]

    def _real_extract(self, url):
        playlist_id = self._match_id(url)
        webpage = self._download_webpage(url, playlist_id)

        title = (self._html_search_regex(
            r'<h1.*?>(.+?)</h1>', webpage, 'title', fatal=False, default=None)
            or self._og_search_title(webpage))
        ppn = self._search_regex(
            r'window\.ppN\s*=\s*([\'"])(?P<ppn>.+?)\1',
            webpage, 'ppn', group='ppn', default=None)

        entries = []
        for episode in re.finditer(
                r'<div class="container-podcast-property">([\s\S]+?)(?:</div>\s*){3}',
                webpage):
            entries.append(self._extract_infos(episode.group(1), ppn=ppn))

        return self.playlist_result(entries, playlist_id, title)


Review comment (suggestion):
```suggestion
        title = (
            self._html_search_regex(
                r'<h1.*?>(.+?)</h1>', webpage, 'title', fatal=False, default=None)
            or self._og_search_title(webpage))
```

Code after:
    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        return self._extract_info(webpage, video_id)


class LA7PodcastIE(LA7PodcastEpisodeIE):
    IE_NAME = 'la7.it:podcast'
    _VALID_URL = r'(https?://)?(www\.)?la7\.it/(?P<id>[^/]+)/podcast/?(?:$|[#?])'

    _TESTS = [{
        'url': 'https://www.la7.it/propagandalive/podcast',
        'info_dict': {
            'id': 'propagandalive',
            'title': "Propaganda Live",
        },
        'playlist_count': 10,
    }]

    def _real_extract(self, url):
        playlist_id = self._match_id(url)
        webpage = self._download_webpage(url, playlist_id)

        title = (
            self._html_search_regex(
                r'<h1.*?>(.+?)</h1>', webpage, 'title', fatal=False, default=None)
            or self._og_search_title(webpage))
        ppn = self._search_regex(
            r'window\.ppN\s*=\s*([\'"])(?P<ppn>.+?)\1',
            webpage, 'ppn', group='ppn', default=None)

        entries = []
        for episode in re.finditer(
                r'<div class="container-podcast-property">([\s\S]+?)(?:</div>\s*){3}',
                webpage):
            entries.append(self._extract_info(episode.group(1), ppn=ppn))

        return self.playlist_result(entries, playlist_id, title)