mik-laj commented on a change in pull request #9833:
URL: https://github.com/apache/airflow/pull/9833#discussion_r455066496



##########
File path: airflow/models/pool.py
##########
@@ -98,19 +100,28 @@ def slots_stats(session: Session = None) -> Dict[str, 
PoolStats]:
         ).all()
 
         # calculate queued and running metrics
+        count: int
         for (pool_name, state, count) in state_count_by_pool:
-            pool = pools.get(pool_name)
-            if not pool:
+            stats_dict: Optional[PoolStats] = pools.get(pool_name)
+            if not stats_dict:
                 continue
-            pool[state] = count
+            # TypedDict key must be a string literal, so we use if-statements 
to set value
+            if state == "running":

Review comment:
       Sorry about that. mypy exploded
   ```
   airflow/models/pool.py:105: error: TypedDict key must be a string literal;
   expected one of ('total', 'running', 'queued')
                   pool[state] = count
                        ^
   airflow/models/pool.py:111: error: TypedDict "PoolStats" has no key 'open'
                       stats["open"] = -1
                             ^
   airflow/models/pool.py:113: error: TypedDict "PoolStats" has no key 'open'
                       stats["open"] = stats["total"] - stats[State.RUNNING] ...
                             ^
   airflow/models/pool.py:113: error: TypedDict key must be a string literal;
   expected one of ('total', 'running', 'queued')
       ...          stats["open"] = stats["total"] - stats[State.RUNNING] - 
stat...
                                                           ^
   airflow/jobs/scheduler_job.py:1754: error: TypedDict "PoolStats" has no key
   'open'
       ...       Stats.gauge(f'pool.open_slots.{pool_name}', slot_stats["open"])
                                                                        ^
   airflow/jobs/scheduler_job.py:1755: error: TypedDict key must be a string
   literal; expected one of ('total', 'running', 'queued')
       ...tats.gauge(f'pool.queued_slots.{pool_name}', slot_stats[State.QUEUED])
                                                                  ^
   airflow/jobs/scheduler_job.py:1756: error: TypedDict key must be a string
   literal; expected one of ('total', 'running', 'queued')
       ...ts.gauge(f'pool.running_slots.{pool_name}', slot_stats[State.RUNNING])
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to