Search code examples
pythonpayment

pyQiwiP2P pay_sources: list[str] = None


I need to make payment via qiwi

from pyqiwip2p import QiwiP2P
from pyqiwip2p.Qiwip2p import PaymentMethods  

def create_trans(amount=400, lifetime=30, comment="def"):
        p2p = QiwiP2P(auth_key="I specifically removed")
        bill = p2p.bill(amount=amount, lifetime=lifetime, comment=comment, bill_id=random_id, pay_sources=[PaymentMethods.qiwi, PaymentMethods.card, PaymentMethods.mobile])
        return bill

The program ends with an error:

File "G:\bot\venv\lib\site-packages\pyqiwip2p\Qiwip2p.py", line 118, in QiwiP2P    
pay_sources: list[str] = None,
TypeError: 'type' object is not subscriptable

Solution

  • This looks to be a bug in pyQiwiP2P.

    As per your traceback, line 118 of pyqiwip2p.Qiwip2p.py is as follows:

            pay_sources: list[str] = None,
    

    This contains a broken type hint, list[str]. It seems the author wanted to add a type hint saying that the method parameter pay_sources should contain a list of strings. In this case, they should write

            pay_sources: typing.List[str] = None,
    

    or perhaps

            pay_sources: typing.Union[typing.List[str], None] = None,
    

    instead, given that pay_sources can also be None.

    To confirm this is the case, we can easily reproduce your exception in a Python interactive session:

    >>> def test(a: list[str]):
    ...     pass
    ...
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'type' object is not subscriptable
    

    I would suggest you get in contact with the package author, perhaps by raising an issue on the project's GitHub repository.