Змея / Говнокод #28439 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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 rockkley94, (Updated )

Комментарии (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))
    Ответить
    • какой всё таки питон некрасивый язык, как волос наелся
      Ответить
        • Точно, так не правильно будет работать. Пофиксил
          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))
          Ответить

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

Я, guest, находясь в здравом уме и твердой памяти, торжественно заявляю:

    А не использовать ли нам bbcode?


    8