1. Python / Говнокод #28439

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    def make_coffie(water_amount: int = 0) -> object:
        
        class Coffie_Constructor:
            
            def __init__(self, beans_amount: int = 0):
                self.water_amount = water_amount
                self.beans_amount = beans_amount
            
            def __call__(self, milk_amount: int = 0) -> int:
                return self.water_amount + self.beans_amount + milk_amount
    
            def __repr__(self) -> str:
                return 'Not enought call brakets were given'
            
        return Coffie_Constructor
    
    print(make_coffie(120)(50)(50))

    Запостил: rockkley94, 09 Ноября 2022

    Комментарии (14) RSS

    • Пофиксил

      def make_coffie(water_amount: int = 0) -> object:
      
          class Coffie_Constructor_Meta(type):
              def __repr__(cls) -> str:
                  return 'Not enought call brakets were given'
          
          class Coffie_Constructor(metaclass=Coffie_Constructor_Meta):
              
              def __init__(self, beans_amount: int = 0):
                  self.water_amount = water_amount
                  self.beans_amount = beans_amount
              
              def __call__(self, milk_amount: int = 0) -> int:
                  return self.water_amount + self.beans_amount + milk_amount
      
              def __repr__(self) -> str:
                  return 'Not enought call brakets were given'
              
          return Coffie_Constructor
      
      print(make_coffie(120)(50)(50))
      Ответить
      • ох, маткабоска. убери это. с глаз.
        Ответить
      • какой всё таки питон некрасивый язык, как волос наелся
        Ответить
      • А можно changelog, зачем доп.мета класс?
        Ответить
        • print(make_coffie)
          Ответить
          • Точно, так не правильно будет работать. Пофиксил
            class MakeCoffieCallable:
                def __call__(self, water_amount: int = 0) -> type:
                    class CoffieConstructorMeta(type):
                        def __repr__(cls) -> str:
                            return 'Not enought call brakets were given'
            
                    class IntLike(int):
                        def __call__(self, _: int = 0) -> str:
                            return 'Too many call brakets were given'
            
                    class CoffieConstructor(metaclass=CoffieConstructorMeta):
                        def __init__(self, beans_amount: int = 0):
                            self.water_amount = water_amount
                            self.beans_amount = beans_amount
            
                        def __call__(self, milk_amount: int = 0) -> int:
                            return IntLike(self.water_amount + self.beans_amount + milk_amount)
            
                        def __repr__(self) -> str:
                            return 'Not enought call brakets were given'
            
                    return CoffieConstructor
            
                def __repr__(self) -> str:
                    return 'Not enought call brakets were given'
            
            
            make_coffie = MakeCoffieCallable()
            
            
            print(make_coffie)
            print(make_coffie(120))
            print(make_coffie(120)(50))
            print(make_coffie(120)(50)(50))
            print(make_coffie(120)(50)(50)(60))
            Ответить
            • Это специальная оплимпиада "вырасти в себе жаваеба"?
              Ответить
            • Coffie Azaza Onan (/ˈkoʊfi ˈʌnʌn/; 8 April 1938 – 18 August 2018) was a Ghanaian diplomat who served as the seventh Secretary-General of the United Nations (UN) from 1997 to 2006. Onan and the UN were the co-recipients of the 2001 Nobel Peace Prize. He was the founder and chairman of ... Wikipedia
              Ответить
            • Прикол в том, что класс в функции, а ты прикол сломал
              Ответить
            • На "PHP" переведи
              Ответить

    Добавить комментарий