changeset 51729:278af66e6595

typing: induce pytype to use the standard `attr` instead of the vendored copy What was previously happening with the vendored copy was that pytype would stub out all(?) classes that were decorated with `@attr.s` as `Any`. After this, we get a ton of classes defined, and numerous fields and methods now have proper types.
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 23 Jul 2024 19:20:22 -0400
parents 2e9e62242451
children 92845af308b4
files hgext/phabricator.py hgext/sqlitestore.py mercurial/bundlecaches.py mercurial/changelog.py mercurial/cmdutil.py mercurial/dagop.py mercurial/dirstateutils/v2.py mercurial/formatter.py mercurial/graphmod.py mercurial/hgweb/request.py mercurial/linelog.py mercurial/logcmdutil.py mercurial/merge.py mercurial/pure/parsers.py mercurial/revlog.py mercurial/revlogutils/__init__.py mercurial/revlogutils/deltas.py mercurial/scmutil.py mercurial/store.py mercurial/util.py mercurial/utils/stringutil.py mercurial/wireprotoframing.py mercurial/wireprototypes.py
diffstat 23 files changed, 158 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/phabricator.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/hgext/phabricator.py	Tue Jul 23 19:20:22 2024 -0400
@@ -68,10 +68,17 @@
 import operator
 import re
 import time
+import typing
 
 from mercurial.node import bin, short
 from mercurial.i18n import _
 from mercurial.thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from mercurial import (
     cmdutil,
     context,
--- a/hgext/sqlitestore.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/hgext/sqlitestore.py	Tue Jul 23 19:20:22 2024 -0400
@@ -47,6 +47,7 @@
 import sqlite3
 import struct
 import threading
+import typing
 import zlib
 
 from mercurial.i18n import _
@@ -56,6 +57,12 @@
     short,
 )
 from mercurial.thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from mercurial import (
     ancestor,
     dagop,
--- a/mercurial/bundlecaches.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/bundlecaches.py	Tue Jul 23 19:20:22 2024 -0400
@@ -4,6 +4,7 @@
 # GNU General Public License version 2 or any later version.
 
 import collections
+import typing
 
 from typing import (
     Dict,
@@ -15,6 +16,11 @@
 
 from .thirdparty import attr
 
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from . import (
     error,
     requirements as requirementsmod,
--- a/mercurial/changelog.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/changelog.py	Tue Jul 23 19:20:22 2024 -0400
@@ -6,6 +6,8 @@
 # GNU General Public License version 2 or any later version.
 
 
+import typing
+
 from .i18n import _
 from .node import (
     bin,
@@ -13,6 +15,11 @@
 )
 from .thirdparty import attr
 
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from . import (
     encoding,
     error,
--- a/mercurial/cmdutil.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/cmdutil.py	Tue Jul 23 19:20:22 2024 -0400
@@ -11,6 +11,7 @@
 import functools
 import os
 import re
+import typing
 
 from typing import (
     Any,
@@ -33,6 +34,11 @@
 )
 from .thirdparty import attr
 
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from . import (
     bookmarks,
     bundle2,
--- a/mercurial/dagop.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/dagop.py	Tue Jul 23 19:20:22 2024 -0400
@@ -7,8 +7,15 @@
 
 
 import heapq
+import typing
 
 from .thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from .node import nullrev
 from . import (
     error,
--- a/mercurial/dirstateutils/v2.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/dirstateutils/v2.py	Tue Jul 23 19:20:22 2024 -0400
@@ -7,8 +7,15 @@
 
 
 import struct
+import typing
 
 from ..thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from .. import error, policy
 
 parsers = policy.importmod('parsers')
--- a/mercurial/formatter.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/formatter.py	Tue Jul 23 19:20:22 2024 -0400
@@ -110,6 +110,7 @@
 import itertools
 import os
 import pickle
+import typing
 
 from .i18n import _
 from .node import (
@@ -118,6 +119,11 @@
 )
 from .thirdparty import attr
 
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from . import (
     error,
     pycompat,
--- a/mercurial/graphmod.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/graphmod.py	Tue Jul 23 19:20:22 2024 -0400
@@ -18,8 +18,16 @@
 """
 
 
+import typing
+
 from .node import nullrev
 from .thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from . import (
     dagop,
     smartset,
--- a/mercurial/hgweb/request.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/hgweb/request.py	Tue Jul 23 19:20:22 2024 -0400
@@ -9,7 +9,15 @@
 
 # import wsgiref.validate
 
+import typing
+
 from ..thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from .. import (
     error,
     pycompat,
--- a/mercurial/linelog.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/linelog.py	Tue Jul 23 19:20:22 2024 -0400
@@ -28,6 +28,12 @@
 )
 
 from .thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from . import pycompat
 
 _llentry = struct.Struct(b'>II')
--- a/mercurial/logcmdutil.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/logcmdutil.py	Tue Jul 23 19:20:22 2024 -0400
@@ -9,6 +9,7 @@
 import itertools
 import os
 import posixpath
+import typing
 
 from typing import (
     Any,
@@ -24,6 +25,11 @@
 
 from .thirdparty import attr
 
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from . import (
     dagop,
     diffutil,
--- a/mercurial/merge.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/merge.py	Tue Jul 23 19:20:22 2024 -0400
@@ -8,10 +8,17 @@
 
 import collections
 import struct
+import typing
 
 from .i18n import _
 from .node import nullrev
 from .thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from .utils import stringutil
 from .dirstateutils import timestamp
 from . import (
--- a/mercurial/pure/parsers.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/pure/parsers.py	Tue Jul 23 19:20:22 2024 -0400
@@ -9,6 +9,7 @@
 import io
 import stat
 import struct
+import typing
 import zlib
 
 from ..node import (
@@ -16,6 +17,12 @@
     sha1nodeconstants,
 )
 from ..thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from .. import (
     error,
     revlogutils,
--- a/mercurial/revlog.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/revlog.py	Tue Jul 23 19:20:22 2024 -0400
@@ -20,6 +20,7 @@
 import io
 import os
 import struct
+import typing
 import weakref
 import zlib
 
@@ -74,6 +75,12 @@
     REVIDX_RAWTEXT_CHANGING_FLAGS,
 )
 from .thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from . import (
     ancestor,
     dagop,
--- a/mercurial/revlogutils/__init__.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/revlogutils/__init__.py	Tue Jul 23 19:20:22 2024 -0400
@@ -6,7 +6,15 @@
 # GNU General Public License version 2 or any later version.
 
 
+import typing
+
 from ..thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from ..interfaces import repository
 
 # See mercurial.revlogutils.constants for doc
--- a/mercurial/revlogutils/deltas.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/revlogutils/deltas.py	Tue Jul 23 19:20:22 2024 -0400
@@ -11,6 +11,7 @@
 import abc
 import collections
 import struct
+import typing
 
 # import stuff from node for others to import from revlog
 from ..node import nullrev
@@ -31,6 +32,11 @@
 
 from ..thirdparty import attr
 
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from .. import (
     error,
     mdiff,
--- a/mercurial/scmutil.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/scmutil.py	Tue Jul 23 19:20:22 2024 -0400
@@ -13,6 +13,7 @@
 import posixpath
 import re
 import subprocess
+import typing
 import weakref
 
 from .i18n import _
@@ -24,6 +25,12 @@
     wdirrev,
 )
 from .thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from . import (
     copies as copiesmod,
     encoding,
--- a/mercurial/store.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/store.py	Tue Jul 23 19:20:22 2024 -0400
@@ -10,10 +10,18 @@
 import os
 import re
 import stat
+import typing
+
 from typing import Generator, List
 
 from .i18n import _
 from .thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from .node import hex
 from .revlogutils.constants import (
     INDEX_HEADER,
--- a/mercurial/util.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/util.py	Tue Jul 23 19:20:22 2024 -0400
@@ -48,6 +48,12 @@
 
 from .node import hex
 from .thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from .pycompat import (
     open,
 )
--- a/mercurial/utils/stringutil.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/utils/stringutil.py	Tue Jul 23 19:20:22 2024 -0400
@@ -13,6 +13,7 @@
 import re as remod
 import textwrap
 import types
+import typing
 
 from typing import (
     Optional,
@@ -22,6 +23,11 @@
 from ..i18n import _
 from ..thirdparty import attr
 
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from .. import (
     encoding,
     error,
--- a/mercurial/wireprotoframing.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/wireprotoframing.py	Tue Jul 23 19:20:22 2024 -0400
@@ -12,9 +12,16 @@
 
 import collections
 import struct
+import typing
 
 from .i18n import _
 from .thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from . import (
     encoding,
     error,
--- a/mercurial/wireprototypes.py	Tue Jul 23 19:14:16 2024 -0400
+++ b/mercurial/wireprototypes.py	Tue Jul 23 19:20:22 2024 -0400
@@ -4,12 +4,20 @@
 # GNU General Public License version 2 or any later version.
 
 
+import typing
+
 from .node import (
     bin,
     hex,
 )
 from .i18n import _
 from .thirdparty import attr
+
+# Force pytype to use the non-vendored package
+if typing.TYPE_CHECKING:
+    # noinspection PyPackageRequirements
+    import attr
+
 from . import (
     error,
     util,