hry-naka / rec-radio

0 stars 0 forks source link

乱暴な初期化 #18

Open hry-naka opened 1 year ago

hry-naka commented 1 year ago

例えば、self.titileが初期化されていないときに、load_now()で初期化しているけど、tfrecを考えると乱暴 そもそもloadしないでgetするのって無謀な気がするので、エラーにするべき (でもユーザ側でエラー処理作る?・・まぁ、どこまでガードするか?はユーザマターでしょって気もする)

  def get_title(self, station, area_id, next_prog=False):
        """
        Get the title of the current or next program for the specified station.

        Args:
            station (str): The ID of the station.
            area_id (str): The ID of the area.
            next_prog (bool): Whether to get the next program. Defaults to False.

        Returns:
            str: The title of the program.
        """
        if next_prog is True:
            index = 1
        else:
            index = 0
        if not self.title:
            self.load_now(station, area_id)
        return self.title[index]
hry-naka commented 1 year ago

そもそも、こんなアクセッサが必要なのか?と思い、今更ですがPythonの文法をお勉強してみると

ということでした。

さて、どうしようかな?

hry-naka commented 1 year ago

言語仕様でガードはかからないでしょうが、pylintとかでチェックしてもらえる可能性はあるので、一応Protectedな定義にはしておく。 セッター・ゲッターは折角@propertyという言語仕様サポートがあるので、活用する。 クラス変数とインスタンス変数の違いは勉強不足でした。

という方針で修正しよう。