Answer the question
In order to leave comments, you need to log in
Python - Can't instantiate an abstract class... with abstract methods?
Can't instantiate abstract class IsAdminFilter with abstract method check.
I've been jumping around for a long time, but I still don't understand what needs to be done, please help.
The code is attached below.
from abc import ABC, abstractmethod
from aiogram import types
from aiogram.dispatcher.filters import BoundFilter
from required import validate
class IsAdminFilter(BoundFilter):
key = 'is_admin'
def __init__(self, is_admin: bool):
self.is_admin = is_admi
async def check(self, message: types.Message):
member = await message.bot.get_chat_member(message.from_user.id, message.chat.id)
return member.is_chat_admin() == self.is_admin
Answer the question
In order to leave comments, you need to log in
The web is initially stateless, that is, the 1st request from Ivan, the 2nd request from Kostya, the 3rd request from Ivan again - are indistinguishable in any way.
To distinguish, to understand that the first and third - from Ivan - session and use.
The indents are oblique, be careful.
You have check() declared as a local function inside __init__(), so there is no such method in the class itself. And since the method is declared abstract in BoundFilter and not overridden in your class, your class remains abstract as well. Therefore, an attempt to create an instance of it fails.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question