typing: suppress a bunch of potential import-error cases in extensions
authorMatt Harbison <matt_harbison@yahoo.com>
Fri, 06 Jan 2023 13:04:50 -0500
changeset 49849 de9ffb82ef4d
parent 49848 139f713010ea
child 49850 bcc45b33efb2
typing: suppress a bunch of potential import-error cases in extensions As flagged by pytype locally. Either the ImportError is locally handled, or the imported module was previously determined to be present by `hgave` (for the phabricator extension), or is handled by the `hgext.convert.subversion` module when imported (for the `hgext.convert.transport` module).
hgext/convert/bzr.py
hgext/convert/subversion.py
hgext/convert/transport.py
hgext/git/gitutil.py
hgext/phabricator.py
hgext/releasenotes.py
hgext/sqlitestore.py
--- a/hgext/convert/bzr.py	Thu Jan 05 00:09:48 2023 -0500
+++ b/hgext/convert/bzr.py	Fri Jan 06 13:04:50 2023 -0500
@@ -31,11 +31,14 @@
 
 try:
     # bazaar imports
+    # pytype: disable=import-error
     import breezy.bzr.bzrdir
     import breezy.errors
     import breezy.revision
     import breezy.revisionspec
 
+    # pytype: enable=import-error
+
     bzrdir = breezy.bzr.bzrdir
     errors = breezy.errors
     revision = breezy.revision
--- a/hgext/convert/subversion.py	Thu Jan 05 00:09:48 2023 -0500
+++ b/hgext/convert/subversion.py	Fri Jan 06 13:04:50 2023 -0500
@@ -47,11 +47,14 @@
 # these bindings.
 
 try:
+    # pytype: disable=import-error
     import svn
     import svn.client
     import svn.core
     import svn.ra
     import svn.delta
+
+    # pytype: enable=import-error
     from . import transport
     import warnings
 
--- a/hgext/convert/transport.py	Thu Jan 05 00:09:48 2023 -0500
+++ b/hgext/convert/transport.py	Fri Jan 06 13:04:50 2023 -0500
@@ -17,10 +17,13 @@
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, see <http://www.gnu.org/licenses/>.
 
+# pytype: disable=import-error
 import svn.client
 import svn.core
 import svn.ra
 
+# pytype: enable=import-error
+
 Pool = svn.core.Pool
 SubversionException = svn.core.SubversionException
 
@@ -37,7 +40,7 @@
 
 def _create_auth_baton(pool):
     """Create a Subversion authentication baton."""
-    import svn.client
+    import svn.client  # pytype: disable=import-error
 
     # Give the client context baton a suite of authentication
     # providers.h
--- a/hgext/git/gitutil.py	Thu Jan 05 00:09:48 2023 -0500
+++ b/hgext/git/gitutil.py	Fri Jan 06 13:04:50 2023 -0500
@@ -9,7 +9,7 @@
     global pygit2_module
     if pygit2_module is None:
         try:
-            import pygit2 as pygit2_module
+            import pygit2 as pygit2_module  # pytype: disable=import-error
 
             pygit2_module.InvalidSpecError
         except (ImportError, AttributeError):
--- a/hgext/phabricator.py	Thu Jan 05 00:09:48 2023 -0500
+++ b/hgext/phabricator.py	Fri Jan 06 13:04:50 2023 -0500
@@ -286,9 +286,12 @@
                 import hgdemandimport
 
                 with hgdemandimport.deactivated():
+                    # pytype: disable=import-error
                     import vcr as vcrmod
                     import vcr.stubs as stubs
 
+                    # pytype: enable=import-error
+
                     vcr = vcrmod.VCR(
                         serializer='json',
                         before_record_request=sanitiserequest,
--- a/hgext/releasenotes.py	Thu Jan 05 00:09:48 2023 -0500
+++ b/hgext/releasenotes.py	Fri Jan 06 13:04:50 2023 -0500
@@ -50,7 +50,7 @@
             module="fuzzywuzzy.fuzz",
         )
 
-        import fuzzywuzzy.fuzz as fuzz
+        import fuzzywuzzy.fuzz as fuzz  # pytype: disable=import-error
 
         fuzz.token_set_ratio
 except ImportError:
--- a/hgext/sqlitestore.py	Thu Jan 05 00:09:48 2023 -0500
+++ b/hgext/sqlitestore.py	Fri Jan 06 13:04:50 2023 -0500
@@ -80,7 +80,7 @@
 )
 
 try:
-    from mercurial import zstd
+    from mercurial import zstd  # pytype: disable=import-error
 
     zstd.__version__
 except ImportError: