## 事象 以下のようにクラスの[[属性 (Python)|属性]]を定義した場合 ```python class Employee: name = "John Doe" ``` [[basedpyright]]でこのようなエラーが出る。 ```error Type annotation for attribute `queryset` is required because this class is not decorated with `@final` [reportUnannotatedClassAttribute] ``` `@final` をつければ解消するが、そもそも無視したい。 ```python @final class Employee: name = "John Doe" ``` ### 環境 | 対象 | バージョン | | ---------------- | ---------- | | [[Python]] | 3.13.11 | | [[basedpyright]] | 1.37.1 | ## 原因 仕様。[[オーバーライド (Python)|オーバーライド]]や継承による型不整合を防ぐため、固定値の[[属性 (Python)|属性]]には[[finalデコレーター (Python)|finalデコレーター]]を付与しないと警告になる。詳細は[[PEP 591]]。 ## 解決方法 [[プロジェクト全体で特定の警告を無視 (basedpyright)|プロジェクト全体で特定の警告を無視]]する。以下いずれか。 ### [[pyrightconfig.json (basedpyright)|pyrightconfig.json]]に設定を追加する ```json { "reportUnannotatedClassAttribute": false } ``` ### [[pyproject.toml]]に設定を追加する ```toml [tool.pyright] reportUnannotatedClassAttribute = false ```