Static abstract method link is not enforced while calling a class
未關閉
還沒有人認領這個 Issue。
stdlib
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- 平均合併
- 1 天 9 小時
- 30 天內合併 PR
- 558
描述
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 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先重現提供的 Python 3.9 範例,並檢查類別方法與靜態方法呼叫所涉及的 abc 和 abstract-method 行為。將觀察到的行為與 issue 中預期的兩個失敗案例進行比較;完成標準是實作預期的強制機制,並包含涵蓋 Parent 和 Child 的回歸測試。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100