Static abstract method link is not enforced while calling a class
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
If you define a method both static and abstract, for example in an interface like concept, you will expect that method to be implemented in all subclasses.
It works fine when calling instances of that child class, raising an exception if the static method is not implemented.
Also, IDE such as Pycharm will warn you that you are doing something fishy.
But you don't get an exception if you simply call the static method.
In the following example I would expect :
- to get an exception while calling Child telling me that this class is not implementing some method properly, such as method1.
- to get an exception while calling Parent static abstract method directly
from abc import ABC, abstractmethod
class Parent(ABC):
@staticmethod
@abstractmethod
def method1():
pass
@staticmethod
@abstractmethod
def method2():
print("Method 2 in Parent")
@abstractmethod
def method3(self):
pass
@abstractmethod
def method4(self):
print("Method 4 in Parent")
class Child(Parent):
@staticmethod
def method2():
print("Method 2 in Child")
def method4(self):
print("Method 4 in Child")
def test_abstract_class():
Parent.method1() # Should complain because calling an abstract class should be forbidden
Parent.method2() # Should complain because calling an abstract class should be forbidden
Child.method1() # Should complain because method was not defined
Child.method2()
print(issubclass(Child, Parent))
Your environment
Python 3.9 on windows 10
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された Python 3.9 の例を再現し、クラスメソッドおよび static-method の呼び出しに関係する abc と abstract-method の挙動を調べます。観測された挙動を issue にある 2 つの想定される失敗ケースと比較します。Parent と Child を対象とする回帰テストによって意図した強制が実装されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100