factory pattern with lambda

How would you create a factory based method using lambda? function signature looks like this. Factory gets a string parameter and returns the instance. class Foo: @abstractmethod def store(factory: Callable[[str], Bar]) obj = factory("abc") // store or call to get instance class Bar: def __init__(self): pass How to call this method using lambda? Foo.store(lambda k:… Read More factory pattern with lambda

Export Postgresql Table to excel with header in Python

My code works but it doesn’t bring the header with the names, it only brings the numbers 0 1 … 10 , what can I do ? Utils_db.py def consulta_sql(sql): try: connection = psycopg2.connect(user="postgres", password="postgres", host="localhost", port="5432", database="tb_cliente") cursor = connection.cursor() except (Exception, psycopg2.Error) as error: try: cursor.execute(sql) connection.commit() except (Exception, psycopg2.Error) as error: finally:… Read More Export Postgresql Table to excel with header in Python

MyPy fails dataclass argument with optional list of objects type

I’m having trouble getting MyPy to pass my script which contains a dataclass Bar with an optional argument foos that holds a list of Foo objects and defaults to an empty list. Stranger still, adding a method Bar.sum_foos() which iterates through self.foos raises a second MyPy error. Am I misunderstanding how to set the correct… Read More MyPy fails dataclass argument with optional list of objects type

Why the TaskCompleted is executed before the end of the operation

I created a task like the following code Task task = new(async () => { // without await Task Delay dont work await Task.Delay(TimeSpan.FromSeconds(5)); Console.WriteLine("Task is down"); }); task.Start(); var awaiter = task.GetAwaiter(); awaiter.OnCompleted(() => { Console.WriteLine("Task is Completed"); }); Why the task completed first is printed and then the task is down The task… Read More Why the TaskCompleted is executed before the end of the operation

type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Client' in type cast in flutter?

I want to get the Client name from the Api using fromMap() method as shown bellow: factory Order.fromMap(Map<String, dynamic> map) { return Order( created_at: Tracker.decode(map[‘created_at’]), id: map[‘id’], updated_at: Tracker.decode(map[‘updated_at’]), total_price: map[‘total_price’], status: map[‘status’], client: map[‘client’] ); } client is an object of Client Model .. I got the following error: type ‘_InternalLinkedHashMap<String, dynamic>’ is not… Read More type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Client' in type cast in flutter?