LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
9.96k stars 1.4k forks source link

TypeError: descriptor '__subclasses__' of 'type' object needs an argument #1177

Closed mengyyy closed 5 years ago

mengyyy commented 5 years ago

When i import DocumentAttributeFilename from telethon.tl.types i get

from telethon.tl.types import DocumentAttributeFilename
TypeError                                 Traceback (most recent call last)
<ipython-input-1-30809b9cf9ef> in <module>
----> 1 from telethon.tl.types import DocumentAttributeFilename

/usr/local/lib/python3.5/dist-packages/telethon/__init__.py in <module>
----> 1 from .client.telegramclient import TelegramClient
      2 from .network import connection
      3 from .tl import types, functions, custom
      4 from .tl.custom import Button
      5 from . import version, events, utils, errors

/usr/local/lib/python3.5/dist-packages/telethon/client/__init__.py in <module>
     11 """
     12 from .telegrambaseclient import TelegramBaseClient
---> 13 from .users import UserMethods  # Required for everything
     14 from .messageparse import MessageParseMethods  # Required for messages
     15 from .uploads import UploadMethods  # Required for messages to send files

/usr/local/lib/python3.5/dist-packages/telethon/client/users.py in <module>
      5
      6 from .telegrambaseclient import TelegramBaseClient
----> 7 from .. import errors, utils, hints
      8 from ..errors import MultiError, RPCError
      9 from ..helpers import retry_range

/usr/local/lib/python3.5/dist-packages/telethon/hints.py in <module>
     52     str,
     53     typing.Type[bytes],
---> 54     io.IOBase
     55 ]
     56

/usr/lib/python3.5/typing.py in __getitem__(self, parameters)
    550             parameters = (parameters,)
    551         return self.__class__(self.__name__, self.__bases__,
--> 552                               dict(self.__dict__), parameters, _root=True)
    553
    554     def __eq__(self, other):

/usr/lib/python3.5/typing.py in __new__(cls, name, bases, namespace, parameters, _root)
    510                 continue
    511             if any(isinstance(t2, type) and issubclass(t1, t2)
--> 512                    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
    513                 all_params.remove(t1)
    514         # It's not a union if there's only one type left.

/usr/lib/python3.5/typing.py in <genexpr>(.0)
    510                 continue
    511             if any(isinstance(t2, type) and issubclass(t1, t2)
--> 512                    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
    513                 all_params.remove(t1)
    514         # It's not a union if there's only one type left.

/usr/lib/python3.5/typing.py in __subclasscheck__(self, cls)
   1075                     return True
   1076                 # If we break out of the loop, the superclass gets a chance.
-> 1077         if super().__subclasscheck__(cls):
   1078             return True
   1079         if self.__extra__ is None or isinstance(cls, GenericMeta):

/usr/lib/python3.5/abc.py in __subclasscheck__(cls, subclass)
    223                 return True
    224         # Check if it's a subclass of a subclass (recursive)
--> 225         for scls in cls.__subclasses__():
    226             if issubclass(subclass, scls):
    227                 cls._abc_cache.add(subclass)

TypeError: descriptor '__subclasses__' of 'type' object needs an argument

But i when i import it send time, this will not happen

try:
     from telethon.tl.types import DocumentAttributeFilename
except:
    from telethon.tl.types import DocumentAttributeFilename
    print(DocumentAttributeFilename)
Lonami commented 5 years ago

What patch of Python 3.5 are you using? (e.g., Python 3.5.1, etc.)

mengyyy commented 5 years ago

Python 3.5.2 (default, Nov 12 2018, 13:43:14)

and from telethon import TelegramClient, events, sync has the same problem

>>> from telethon import TelegramClient, events, sync
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/telethon/__init__.py", line 1, in <module>
    from .client.telegramclient import TelegramClient
  File "/usr/local/lib/python3.5/dist-packages/telethon/client/__init__.py", line 13, in <module>
    from .users import UserMethods  # Required for everything
  File "/usr/local/lib/python3.5/dist-packages/telethon/client/users.py", line 7, in <module>
    from .. import errors, utils, hints
  File "/usr/local/lib/python3.5/dist-packages/telethon/hints.py", line 54, in <module>
    io.IOBase
  File "/usr/lib/python3.5/typing.py", line 552, in __getitem__
    dict(self.__dict__), parameters, _root=True)
  File "/usr/lib/python3.5/typing.py", line 512, in __new__
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
  File "/usr/lib/python3.5/typing.py", line 512, in <genexpr>
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
  File "/usr/lib/python3.5/typing.py", line 1077, in __subclasscheck__
    if super().__subclasscheck__(cls):
  File "/usr/lib/python3.5/abc.py", line 225, in __subclasscheck__
    for scls in cls.__subclasses__():
TypeError: descriptor '__subclasses__' of 'type' object needs an argument
Lonami commented 5 years ago

Unfortunately I cannot install Python 3.5.2 on my system (tried both manually and with pyenv), because it requires such an old OpenSSL version that is no longer easily available :(

This was apparently reported at https://github.com/python/typing/issues/266 and fixed by https://github.com/python/typing/pull/267 so I'll see what I can do about it.

Lonami commented 5 years ago

This might actually just be a better fix altogether, instead of some hacky workaround. Also, consider upgrading. 3.5.2 is ancient and you're missing all the good stuff.

mengyyy commented 5 years ago

Thank you i have changed to python 3.7.3

Lonami commented 5 years ago

Could you test 3.5.2 just to see if it got fixed anyway? After that, you can use 3.7.3 all you want.

s-boris commented 5 years ago

Just tried to run telethon on python 3.5.2. it doesn't seem like the fix worked

Traceback (most recent call last):
  File "/mnt/d/Dev/WTT-Bridge/run.py", line 5, in <module>
    import src.telegram_selfbot as tgs
  File "/mnt/d/Dev/WTT-Bridge/src/telegram_selfbot.py", line 1, in <module>
    from telethon.sync import TelegramClient
  File "/home/Boro/.local/lib/python3.5/site-packages/telethon/__init__.py", line 1, in <module>
    from .client.telegramclient import TelegramClient
  File "/home/Boro/.local/lib/python3.5/site-packages/telethon/client/__init__.py", line 13, in <module>
    from .users import UserMethods  # Required for everything
  File "/home/Boro/.local/lib/python3.5/site-packages/telethon/client/users.py", line 7, in <module>
    from .. import errors, utils, hints
  File "/home/Boro/.local/lib/python3.5/site-packages/telethon/hints.py", line 56, in <module>
    typing.BinaryIO
  File "/usr/lib/python3.5/typing.py", line 552, in __getitem__
    dict(self.__dict__), parameters, _root=True)
  File "/usr/lib/python3.5/typing.py", line 512, in __new__
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
  File "/usr/lib/python3.5/typing.py", line 512, in <genexpr>
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
  File "/usr/lib/python3.5/typing.py", line 1077, in __subclasscheck__
    if super().__subclasscheck__(cls):
  File "/usr/lib/python3.5/abc.py", line 225, in __subclasscheck__
    for scls in cls.__subclasses__():
TypeError: descriptor '__subclasses__' of 'type' object needs an argument
Lonami commented 5 years ago

Did you install from GitHub or from PyPi?

s-boris commented 5 years ago

Did you install from GitHub or from PyPi?

from github with pip3 install -U https://github.com/LonamiWebs/Telethon/archive/master.zip --user My traceback mentions typing.BinaryIO instead of io.IOBase like in @mengyyy s post