             (setf python-watched-config-files
                   (assoc-delete-all config-file python-watched-config-files))))
 
-        (pcase-dolist (`(,config-file . ,_) python-pre-commit-config-cache)
-          (when (string-prefix-p root config-file)
-            (setf python-pre-commit-config-cache
-                  (assoc-delete-all config-file python-pre-commit-config-cache))))
-
-        (pcase-dolist (`(,config-file . ,_) python-pyproject-cache)
-          (when (string-prefix-p root config-file)
-            (setf python-pyproject-cache
-                  (assoc-delete-all config-file python-pyproject-cache)))))
+        (dolist (cache '(python-pre-commit-config-cache python-pyproject-cache))
+          (pcase-dolist (`(,config-file . ,_) (symbol-value cache))
+            (when (string-prefix-p root config-file)
+              (setf (symbol-value cache)
+                    (assoc-delete-all config-file (symbol-value cache)))))))
 
       (setf python-project-requirements-cache
             (assoc-delete-all buf-file python-project-requirements-cache)))))

                              (funcall parser file))))))))
          python-watched-config-files)))

(defun python-pre-commit-config-path ()
  (find-file-from-project-root ".pre-commit-config.yaml"))

(defvar python-pre-commit-config-cache nil)
(defun python-pre-commit-config ()
  (let* ((config-path (python-pre-commit-config-path))
         (cache-value (assoc-default config-path python-pre-commit-config-cache)))
    (if cache-value
        cache-value
      (python-watch-config-file config-path 'python-pre-commit-config-cache 'python-parse-config-file)
      (when-let ((content (python-parse-config-file config-path)))
        (push (cons config-path content) python-pre-commit-config-cache)
        content))))

(defun python-pyproject-path ()
  (find-file-from-project-root "pyproject.toml"))

(defun python-use-poetry-p ()
  (when-let ((pyproject-path (python-pyproject-path)))
    (and
     (with-temp-buffer
       (insert-file-contents pyproject-path)


              (db
               (or (assoc-default db-file python-pre-commit-database-cache)
                   (when (file-exists-p db-file)
                     (python-watch-config-file db-file 'python-pre-commit-database-cache 'python-parse-pre-commit-db)
                     (when-let ((content (python-parse-pre-commit-db db-file)))
                       (push (cons db-file content) python-pre-commit-database-cache)
                       content))))

              (repo-config
               (seq-find
