Changeset View
Standalone View
swh/loader/mercurial/hgutil.py
# Copyright (C) 2020-2021 The Software Heritage developers | # Copyright (C) 2020-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from collections import defaultdict | from collections import defaultdict | ||||
from dataclasses import dataclass | from dataclasses import dataclass | ||||
import io | import io | ||||
import os | import os | ||||
import signal | import signal | ||||
import time | import time | ||||
import traceback | import traceback | ||||
from typing import Dict, List, Mapping, NewType, Optional, Set | from typing import Dict, List, Mapping, Optional, Set | ||||
from billiard import Process, Queue | from billiard import Process, Queue | ||||
# The internal Mercurial API is not guaranteed to be stable. | # The internal Mercurial API is not guaranteed to be stable. | ||||
from mercurial import bookmarks, context, error, hg, smartset, util # type: ignore | from mercurial import bookmarks, context, error, hg, smartset, util # type: ignore | ||||
import mercurial.ui # type: ignore | import mercurial.ui # type: ignore | ||||
NULLID = mercurial.node.nullid | NULLID = mercurial.node.nullid | ||||
HgNodeId = NewType("HgNodeId", bytes) | HgNodeId = bytes | ||||
ardumont: I dropped this because mypy was unhappy about it (with the use
of it within the from_disk… | |||||
olasdUnsubmitted Not Done Inline ActionsWell the point is to make an alias of bytes that /cannot/ be mistaken for raw bytes. If mypy is unhappy, this means that the typing is unsound somehow. olasd: Well the point is to make an alias of bytes that /cannot/ be mistaken for raw bytes.
If mypy… | |||||
ardumontAuthorUnsubmitted Done Inline ActionsWell, i can also revert and let the bytes flow everywhere. I was not attempting to untangle deep typing issues (i've no idea what that NewType is). ardumont: Well, i can also revert and let the bytes flow everywhere.
I was merely trying to make sense of… | |||||
ardumontAuthorUnsubmitted Done Inline Actions> Well, i can also revert a... That was supposedly destroyed ^ ¯\_(ツ)_/¯ ardumont: > Well, i can also revert a...
That was supposedly destroyed ^ ¯\_(ツ)_/¯ | |||||
olasdUnsubmitted Not Done Inline Actions(I assume that this is not a problem anymore with the update to the signature of _get_extids_for_targets) olasd: (I assume that this is not a problem anymore with the update to the signature of… | |||||
ardumontAuthorUnsubmitted Done Inline ActionsNope it still is. $ mypy swh swh/loader/mercurial/from_disk.py:264: error: Generator has incompatible item type "bytes"; expected "HgNodeId" swh/loader/mercurial/from_disk.py:267: error: Generator has incompatible item type "bytes"; expected "HgNodeId" swh/loader/mercurial/from_disk.py:279: error: Invalid index type "bytes" for "Dict[HgNodeId, bytes]"; expected type "HgNodeId" swh/loader/mercurial/from_disk.py:299: error: Argument 2 to "extid_get_from_extid" of "StorageInterface" has incompatible type "List[HgNodeId]"; expected "List[bytes]" swh/loader/mercurial/from_disk.py:299: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance swh/loader/mercurial/from_disk.py:299: note: Consider using "Sequence" instead, which is covariant swh/loader/mercurial/from_disk.py:303: error: Invalid index type "bytes" for "Dict[HgNodeId, bytes]"; expected type "HgNodeId" swh/loader/mercurial/from_disk.py:386: error: List comprehension has incompatible type List[bytes]; expected List[HgNodeId] Found 6 errors in 1 file (checked 28 source files) ardumont: Nope it still is.
It's at the frontier with the StorageInterface that comes problems or… | |||||
ardumontAuthorUnsubmitted Done Inline Actionsand of course, swh/loader/mercurial/from_disk.py:279: error: Cannot use isinstance() with NewType type ardumont: and of course, `swh/loader/mercurial/from_disk.py:279: error: Cannot use isinstance() with… | |||||
ardumontAuthorUnsubmitted Done Inline ActionsTo avoid making nico repeat himself. 18:19 <+olasd> supposedly this avoids the mistake that happened in the blablabla_from_targets(targets: List[HgNodeId]) signature 18:20 <+olasd> where you passed a list of bytes that weren't really NodeIds 18:21 <+olasd> most of them can probably be fixed An update for the diff is ongoing. ardumont: To avoid making nico repeat himself.
```
18:19 <+olasd> supposedly this avoids the mistake that… | |||||
Repository = hg.localrepo | Repository = hg.localrepo | ||||
BaseContext = context.basectx | BaseContext = context.basectx | ||||
LRUCacheDict = util.lrucachedict | LRUCacheDict = util.lrucachedict | ||||
HgSpanSet = smartset._spanset | HgSpanSet = smartset._spanset | ||||
HgFilteredSet = smartset.filteredset | HgFilteredSet = smartset.filteredset | ||||
LookupError = error.LookupError | LookupError = error.LookupError | ||||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |
I dropped this because mypy was unhappy about it (with the use
of it within the from_disk implementation i mean).
We just want an alias on bytes here so i kept it simpler.