applying Singleton to Spotipy throws error

Question:

Spotipy’s object needs to be passed a credential kw arg
my code:

import spotipy
class Spoti2(spotipy.Spotify):
    spoty_obj = None
    
    @classmethod
    def __new__(cls, client_credentials_manager):
        if cls.spoty_obj is None:
            cls.spoty_obj = super().__new__(cls)
            print('se creo instancia')
        return cls.spoty_obj

but i get the error:

Spoti2.__new__() got multiple values for argument 'client_credentials_manager'

however, when I remove @classmethod, it works, and I don’t know why

Asked By: kukelia

||

Answers:

You’re not supposed to add @classmethod to __new__()

From: https://docs.python.org/3/reference/datamodel.html#object.__new__

special-cased so you need not declare it as [a static/class method]

Answered By: Kache