D
D
DmitriyKobrin2022-02-14 12:13:24
meteor
DmitriyKobrin, 2022-02-14 12:13:24

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

4 answer(s)
A
Alexey P, 2016-02-23
@sarkis-tlt

How do you differentiate between users?

W
werw, 2016-02-23
@werw

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.

R
Roman Kitaev, 2022-02-14
@deliro

An abstract class is abstract because it cannot be instantiated.

V
Vindicar, 2022-02-14
@Vindicar

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 question

Ask a Question

731 491 924 answers to any question