Fri, 20 Sep 2024 13:38:13 -0400 typing: run `merge-pyi` on `mercurial/vfs.py`
Matt Harbison <matt_harbison@yahoo.com> [Fri, 20 Sep 2024 13:38:13 -0400] rev 51890
typing: run `merge-pyi` on `mercurial/vfs.py` The *.pyi file was generated with pytype 2023.11.21. There were a few things here that were wrong (e.g. `writelines()` takes an `Iterable[bytes]`, not `bytes`, or inexplicable errors like importing several of the vfs classes from this very module), and those changes have been dropped manually here.
Fri, 20 Sep 2024 01:10:17 -0400 typing: add type annotations to `mercurial.util.makelock()`
Matt Harbison <matt_harbison@yahoo.com> [Fri, 20 Sep 2024 01:10:17 -0400] rev 51889
typing: add type annotations to `mercurial.util.makelock()` This bubbles up into the `vfs` classes, so get this out of the way.
Fri, 20 Sep 2024 00:20:24 -0400 util: avoid a leaked file descriptor in `util.makelock()` exceptional case
Matt Harbison <matt_harbison@yahoo.com> [Fri, 20 Sep 2024 00:20:24 -0400] rev 51888
util: avoid a leaked file descriptor in `util.makelock()` exceptional case
Fri, 20 Sep 2024 00:04:09 -0400 typing: add type annotations to the `mercurial.util.filestat` class
Matt Harbison <matt_harbison@yahoo.com> [Fri, 20 Sep 2024 00:04:09 -0400] rev 51887
typing: add type annotations to the `mercurial.util.filestat` class It's referenced in the `vfs` classes, so get this out of the way to help there. The `TypeVar` definition and its usage was copied from the existing `util.pyi` file.
Fri, 20 Sep 2024 12:15:08 -0400 vfs: do minor copyediting on comments and doc strings
Matt Harbison <matt_harbison@yahoo.com> [Fri, 20 Sep 2024 12:15:08 -0400] rev 51886
vfs: do minor copyediting on comments and doc strings These were flagged by PyCharm, so clear them from the gutter.
Fri, 20 Sep 2024 01:16:16 -0400 vfs: simplify the `abstractvfs.rename()` implementation
Matt Harbison <matt_harbison@yahoo.com> [Fri, 20 Sep 2024 01:16:16 -0400] rev 51885
vfs: simplify the `abstractvfs.rename()` implementation PyCharm was yapping about `util.rename()` not returning anything, because it is typed to return `None`, but the value was captured and returned after calling `_avoidambig()`. Instead, drop all of that, unconditionally rename, and then call `_avoidambig()` if appropriate. While we're here, convert the ersatz ternary operator into a modern one to help pytype. When a variable is initialized the old way, pytype tends to assign the type of the LHS of the `and`. In this case, that's a bool, and it will get confused that bool doesn't have a `stat` attribute once this method gets more type annotations. (Currently it thinks the `checkambig` arg is `Any`, so it doesn't care.)
Fri, 20 Sep 2024 00:07:39 -0400 vfs: use @abstractmethod instead of homebrewing abstract methods
Matt Harbison <matt_harbison@yahoo.com> [Fri, 20 Sep 2024 00:07:39 -0400] rev 51884
vfs: use @abstractmethod instead of homebrewing abstract methods The latter confuses PyCharm after adding more type annotations when, for example, `abstractvfs.rename()` calls `_auditpath()`- the latter unconditionally raised an error, so PyCharm thought the code that came after is unreachable. It also tricked pytype into marking the return type as `Never`, which isn't available until Python 3.11 (outside of `typing_extensions`). This also avoid PyCharm warnings that the call to the superclass constructor was missed (it couldn't be called because it raised an error to prevent instantiation). The statichttprepo module needed to be given an override for one of the abstract methods, so that it can be instantiated. In `abstractvfs`, this method is only called by `rename()`, so I think we can leave this empty. We raise an error in case somebody accidentally calls it in the future- it would have raised this same error prior to this change. I couldn't wrangle `import-checker.py` into accepting importing `ABC` and `abstractmethod`- for each subsequent import, it reports something like: stdlib import "contextlib" follows local import: abc I suspect the problem is that near the `if fullname != '__future__'` check, if the module doesn't fall into the error case, `seenlocal` gets set to the module name. That causes it to be treated like a local module on the next iteration, even though it is in `stdlib_modules`.
Thu, 19 Sep 2024 21:03:10 -0400 vfs: modernize the detection of the main thread
Matt Harbison <matt_harbison@yahoo.com> [Thu, 19 Sep 2024 21:03:10 -0400] rev 51883
vfs: modernize the detection of the main thread There weren't a lot of good choices when py27 was supported, but starting with py34, `threading.main_thread()` is available. This gets us away from an undocumented, internal symbol, and drops a pytype suppression statement. It is also apparently no longer reliable after a process fork.[1][2] [1] https://stackoverflow.com/a/23207116 [2] https://github.com/python/cpython/blob/v3.6.3/Lib/threading.py#L1334
Sun, 22 Sep 2024 17:06:31 -0400 store: fix a signature mismatch for a vfs subclass
Matt Harbison <matt_harbison@yahoo.com> [Sun, 22 Sep 2024 17:06:31 -0400] rev 51882
store: fix a signature mismatch for a vfs subclass This was flagged by PyCharm. I'm not sure why pytype doesn't catch this- it's not excluded from the modules that are currently checked.
Sun, 22 Sep 2024 17:02:42 -0400 lfs: fix various signature mismatches for vfs subclasses
Matt Harbison <matt_harbison@yahoo.com> [Sun, 22 Sep 2024 17:02:42 -0400] rev 51881
lfs: fix various signature mismatches for vfs subclasses These were flagged by PyCharm. I'm not sure why pytype doesn't catch these- only `hgext/lfs/__init__.py` in the lfs extension is excluded from being checked. I'm not sure if the `*insidef` arg to `join()` was meant as an internal convencience, because I see another class that gets flagged for the same signature problem (to be fixed next). But I don't feel bold enough to make this an internal function, and provide a simplified public `join()` on the `vfs` classes. That can still be done later, if desired. For now, process the additional args and pass them along, even though there don't appear to be any current callers that provide extra args to these classes. We need all of the subclasses to agree on the signature, or they won't be considered to implement the `Vfs` protocol being developed. While we're copy/pasting from the base class, bring the type annotations along for the ride.
Sun, 22 Sep 2024 17:18:05 -0400 util: add a comment to suppress a PyCharm warning about a PEP 8 violation
Matt Harbison <matt_harbison@yahoo.com> [Sun, 22 Sep 2024 17:18:05 -0400] rev 51880
util: add a comment to suppress a PyCharm warning about a PEP 8 violation Slowly trying to get rid of silly warnings, so that real problems aren't hidden.
Sun, 22 Sep 2024 17:15:20 -0400 keepalive: fix a signature mismatch for a http.client.HTTPResponse subclass
Matt Harbison <matt_harbison@yahoo.com> [Sun, 22 Sep 2024 17:15:20 -0400] rev 51879
keepalive: fix a signature mismatch for a http.client.HTTPResponse subclass Also flagged by PyCharm. This is checked by pytype too, so I'm not sure why it misses this. I verified in py36 that this argument is documented for the function, so maybe this is py2 legacy.
Sun, 22 Sep 2024 17:11:10 -0400 cbor: drop a duplicate dictionary initialization entry
Matt Harbison <matt_harbison@yahoo.com> [Sun, 22 Sep 2024 17:11:10 -0400] rev 51878
cbor: drop a duplicate dictionary initialization entry Flagged by PyCharm.
Wed, 04 Sep 2024 17:08:58 +0200 profiling: document the py-spy value for `profiling.type`
Pierre-Yves David <pierre-yves.david@octobus.net> [Wed, 04 Sep 2024 17:08:58 +0200] rev 51877
profiling: document the py-spy value for `profiling.type` The feature was not visible otherwise.
Thu, 19 Sep 2024 18:49:04 -0400 tests: enable pytype checking on `mercurial/unionrepo.py`
Matt Harbison <matt_harbison@yahoo.com> [Thu, 19 Sep 2024 18:49:04 -0400] rev 51876
tests: enable pytype checking on `mercurial/unionrepo.py`
Thu, 19 Sep 2024 18:48:07 -0400 unionrepo: fix mismatches with revlog classes
Matt Harbison <matt_harbison@yahoo.com> [Thu, 19 Sep 2024 18:48:07 -0400] rev 51875
unionrepo: fix mismatches with revlog classes This is a subset of cfd30df0f8e4, applied to `unionrepository`. There are none of the `write()` method overrides here, like `bundlerepository`. With these changes, pytype flags the `unionrevlog` constructor: File "/mnt/c/Users/Matt/hg/mercurial/unionrepo.py", line 55, in __init__: No attribute '_revlog' on mercurial.changelog.changelog [attribute-error] Called from (traceback): line 207, in __init__ File "/mnt/c/Users/Matt/hg/mercurial/unionrepo.py", line 55, in __init__: No attribute '_revlog' on mercurial.revlog.revlog [attribute-error] Called from (traceback): line 232, in __init__ But it turns out that both `changelog.changelog` and `revlog.revlog` do have a `target` attribute, so they wouldn't trip over this. It seems weird that the second caller to be flagged is passing the private `_revlog`, but maybe that's how it needs to be.
Thu, 19 Sep 2024 16:19:29 -0400 typing: make `unionrepository` subclass `localrepository` while type checking
Matt Harbison <matt_harbison@yahoo.com> [Thu, 19 Sep 2024 16:19:29 -0400] rev 51874
typing: make `unionrepository` subclass `localrepository` while type checking This is the same change as 9d4ad05bc91c made for `bundlerepository`, for the same reasons. Also, add a comment here to suppress the PyCharm warning that the superclass constructor is not called, that is new now that there's a simulated superclass. That lack of a call is by design- `makeunionrepository()` does magic that PyCharm isn't aware of. But PyCharm has been better at catching problems than pytype in a lot of cases, so I'd like to reduce the bogus things it flags, to make the real issues stand out.
Wed, 18 Sep 2024 21:00:20 -0400 tests: enable pytype checking on `mercurial/bundlerepo.py`
Matt Harbison <matt_harbison@yahoo.com> [Wed, 18 Sep 2024 21:00:20 -0400] rev 51873
tests: enable pytype checking on `mercurial/bundlerepo.py`
Wed, 18 Sep 2024 17:46:46 -0400 revlog: make `clearcaches()` signature consistent with ManifestRevlog
Matt Harbison <matt_harbison@yahoo.com> [Wed, 18 Sep 2024 17:46:46 -0400] rev 51872
revlog: make `clearcaches()` signature consistent with ManifestRevlog I'm not sure if this a newly added bug, because of using a different version of pytype, or if the recent work around avoiding the zope interface types in the type checking phase (see 5eb98ea78fd7 and friends)... but pytype 2023.11.21 started flagging this series since it was last pushed ~6 weeks ago: File "/mnt/c/Users/Matt/hg/mercurial/bundlerepo.py", line 204, in <module>: Overriding method signature mismatch [signature-mismatch] Base signature: 'def mercurial.manifest.ManifestRevlog.clearcaches(self, clear_persisted_data: Any = ...) -> None'. Subclass signature: 'def mercurial.revlog.revlog.clearcaches(self) -> None'. Not enough positional parameters in overriding method. Maybe the multiple inheritance in `bundlerepo.bundlemanifest` is bad, but it seems like a `ManifestRevlog` is-a `revlog`, even though the class hierarchy isn't coded that way. Additionally, it looks like `revlog.clearcaches()` is dealing with some persistent data, so maybe this is useful to have there anyway. Also sprinkle some trivial type hints on the method, because there are other `clearcaches()` definitions in the codebase with these hints, and I don't feel like waiting for another pytype run to see if it cares that specifically about the signature matching.
Sat, 03 Aug 2024 01:33:13 -0400 bundlerepo: fix mismatches with repository and revlog classes
Matt Harbison <matt_harbison@yahoo.com> [Sat, 03 Aug 2024 01:33:13 -0400] rev 51871
bundlerepo: fix mismatches with repository and revlog classes Both pytype and PyCharm complained that `write()` and `_write()` in the bundlephasecache class aren't proper overrides- indeed they seem to be missing an argument that the base class has. PyCharm and pytype also complained that the `revlog.revlog` class doesn't have a `_chunk()` method. That looks like it was moved from revlog to `_InnerRevlog` back in e8ad6d8de8b8, and wasn't caught because this module wasn't type checked. However, I couldn't figure out a syntax with `revlog.revlog._inner._chunk(self, rev)`, as it complained about passing too many args. `bundlerevlog._rawtext()` uses this `super(...)` style to call the super class, so hopefully that works, even with the wonky dynamic subclassing. The revlog class needed the `_InnerRevlog` field typed because it isn't set in the constructor. Finally, the vfs type hints look broken. This initially failed with: File "/mnt/c/Users/Matt/hg/mercurial/bundlerepo.py", line 65, in __init__: Function readonlyvfs.__init__ was called with the wrong arguments [wrong-arg-types] Expected: (self, vfs: mercurial.vfs.vfs) Actually passed: (self, vfs: Callable) Called from (traceback): line 232, in dirlog line 214, in __init__ I don't see a raw Callable, but I tried changing some of the vfs args to be typed as `vfsmod.abstractvfs`, but that class doesn't have `options`, so it failed elsewhere. `readonlyvfs` isn't a subclass of `vfs` (it's a subclass of `abstractvfs`), so I'm not sure how to handle that. It would be a shame to have to make a union of vfs subclasses (but not all of them have `options` either).
Wed, 18 Sep 2024 17:50:57 -0400 typing: make `bundlerepository` subclass `localrepository` while type checking
Matt Harbison <matt_harbison@yahoo.com> [Wed, 18 Sep 2024 17:50:57 -0400] rev 51870
typing: make `bundlerepository` subclass `localrepository` while type checking Currently, `mercurial/bundlerepo.py` is excluded from pytype, mostly because it complains that various `ui` and `vfs` fields in `localrepository` are missing. (`bundlerepository` dynamically subclasses `localrepository` when it is instantiated, so it works at runtime.) This makes that class hierarchy known to pytype. Having a protocol for `Repository` is probably the right thing to do, but that will be a lot of work and this still reflects the class at runtime. Subclassing also has the benefit of making sure any method overrides have a matching signature, so maybe this is a situation where we do both of these things. (I'm not sure how clear the diagnostics are if a class *almost* implements a protocol, but is missing a method argument or similar.) The subclassing is not done outside of type checking runs to avoid any side effects on already complex code.
Tue, 17 Sep 2024 16:40:24 +0200 rust: bump rust-cpython version to 0.7.2 stable
Pierre-Yves David <pierre-yves.david@octobus.net> [Tue, 17 Sep 2024 16:40:24 +0200] rev 51869
rust: bump rust-cpython version to 0.7.2 This version supports Python 3.12 while 0.7.1 did not.
Wed, 19 Jun 2024 14:49:35 +0200 rust: add Vfs trait
Raphaël Gomès <rgomes@octobus.net> [Wed, 19 Jun 2024 14:49:35 +0200] rev 51868
rust: add Vfs trait This will allow for the use of multiple vfs like in the Python implementation, as well as hiding the details of the upcoming Python vfs wrapper to hg-core.
Wed, 19 Jun 2024 12:49:26 +0200 rust: use new revlog configs in all revlog opening code
Raphaël Gomès <rgomes@octobus.net> [Wed, 19 Jun 2024 12:49:26 +0200] rev 51867
rust: use new revlog configs in all revlog opening code This centralizes the more complex logic needed for the upcoming code and creates stronger APIs with fewer booleans. We also reuse `RevlogType` where needed.
(0) -30000 -10000 -3000 -1000 -300 -100 -50 -24 +24 +50 +100 +300 tip