[PATCH 1 of 2] py3: protect from exceptions thrown by other meta-path finders

Yuya Nishihara yuya at tcha.org
Mon Apr 22 19:21:09 EDT 2019


On Fri, 19 Apr 2019 14:34:13 +0000, Ludovic Chabant wrote:
> # HG changeset patch
> # User Ludovic Chabant <ludovic at chabant.com>
> # Date 1555683918 0
> #      Fri Apr 19 14:25:18 2019 +0000
> # Branch stable
> # Node ID 96a51193678400abf9d04af65e60a8dccf540cd7
> # Parent  4a8d9ed864754837a185a642170cde24392f9abf
> py3: protect from exceptions thrown by other meta-path finders
> 
> diff --git a/mercurial/__init__.py b/mercurial/__init__.py
> --- a/mercurial/__init__.py
> +++ b/mercurial/__init__.py
> @@ -54,9 +54,14 @@
>                  if finder == self:
>                      continue
>  
> -                spec = finder.find_spec(fullname, path, target=target)
> -                if spec:
> -                    break
> +                try:
> +                    spec = finder.find_spec(fullname, path, target=target)
> +                    if spec:
> +                        break
> +                except:
> +                    # Some finders don't implement `find_spec`, like
> +                    # `_SixMetaPathImporter`.
> +                    pass

Is there any list of exceptions that are known to be safely suppressed?
Catching AttributeError, TypeError, etc. seems bad.


More information about the Mercurial-devel mailing list