Mercurial > hg-stable
view mercurial/revlogutils/__init__.py @ 51901:f4733654f144
typing: add `from __future__ import annotations` to most files
Now that py36 is no longer supported, we can postpone annotation evaluation.
This means that the quoting is usually optional (for things imported under the
guard of `if typing.TYPE_CHECKING:` to avoid circular imports), and there's less
overhead on startup[1].
There may be some missing here. I backed out 6000f5b25c9b (which removed the
`from __future__ import ...` that was supporting py2), reverted the changes in
`contrib/`, `doc/`, and `tests/`, and then ran:
$ hg status -n --change . | \
xargs sed -i -e 's/from __future__ import .*$/from __future__ import annotations/'
There were some minor tweaks needed when reviewing (mostly making the spacing
around the import consistent, and `mercurial/testing/__init__.py` had a
multiline import that wasn't fully rewritten.
[1] https://docs.python.org/3/whatsnew/3.7.html#pep-563-postponed-evaluation-of-annotations
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 16 Sep 2024 15:36:44 +0200 |
parents | 278af66e6595 |
children |
line wrap: on
line source
# mercurial.revlogutils -- basic utilities for revlog # # Copyright 2019 Pierre-Yves David <pierre-yves.david@octobus.net> # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. from __future__ import annotations 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 COMP_MODE_INLINE = 2 RANK_UNKNOWN = -1 def offset_type(offset, type): if (type & ~repository.REVISION_FLAGS_KNOWN) != 0: raise ValueError(b'unknown revlog index flags: %d' % type) return int(int(offset) << 16 | type) def entry( data_offset, data_compressed_length, data_delta_base, link_rev, parent_rev_1, parent_rev_2, node_id, flags=0, data_uncompressed_length=-1, data_compression_mode=COMP_MODE_INLINE, sidedata_offset=0, sidedata_compressed_length=0, sidedata_compression_mode=COMP_MODE_INLINE, rank=RANK_UNKNOWN, ): """Build one entry from symbolic name This is useful to abstract the actual detail of how we build the entry tuple for caller who don't care about it. This should always be called using keyword arguments. Some arguments have default value, this match the value used by index version that does not store such data. """ return ( offset_type(data_offset, flags), data_compressed_length, data_uncompressed_length, data_delta_base, link_rev, parent_rev_1, parent_rev_2, node_id, sidedata_offset, sidedata_compressed_length, data_compression_mode, sidedata_compression_mode, rank, ) @attr.s(slots=True, frozen=True) class revisioninfo: """Information about a revision that allows building its fulltext node: expected hash of the revision p1, p2: parent revs of the revision (as node) btext: built text cache consisting of a one-element list cachedelta: (baserev, uncompressed_delta, usage_mode) or None flags: flags associated to the revision storage One of btext[0] or cachedelta must be set. """ node = attr.ib() p1 = attr.ib() p2 = attr.ib() btext = attr.ib() textlen = attr.ib() cachedelta = attr.ib() flags = attr.ib()