# HG changeset patch # User Matt Harbison # Date 1721776822 14400 # Node ID 278af66e6595ff3baff92416839f7dbc427e24fd # Parent 2e9e6224245185097fbf2da0f81e4897288f4fda 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. diff -r 2e9e62242451 -r 278af66e6595 hgext/phabricator.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 hgext/sqlitestore.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/bundlecaches.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/changelog.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/cmdutil.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/dagop.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/dirstateutils/v2.py --- 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') diff -r 2e9e62242451 -r 278af66e6595 mercurial/formatter.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/graphmod.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/hgweb/request.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/linelog.py --- 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') diff -r 2e9e62242451 -r 278af66e6595 mercurial/logcmdutil.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/merge.py --- 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 ( diff -r 2e9e62242451 -r 278af66e6595 mercurial/pure/parsers.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/revlog.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/revlogutils/__init__.py --- 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 diff -r 2e9e62242451 -r 278af66e6595 mercurial/revlogutils/deltas.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/scmutil.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/store.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/util.py --- 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, ) diff -r 2e9e62242451 -r 278af66e6595 mercurial/utils/stringutil.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/wireprotoframing.py --- 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, diff -r 2e9e62242451 -r 278af66e6595 mercurial/wireprototypes.py --- 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,