# HG changeset patch # User Matt Harbison # Date 1726696257 14400 # Node ID 9d4ad05bc91c70c4023cc00050b7354b0a9f6854 # Parent db7dbe6f7bb2b7eca836fcc38fb0c2cd85c96ee7 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. diff -r db7dbe6f7bb2 -r 9d4ad05bc91c mercurial/bundlerepo.py --- a/mercurial/bundlerepo.py Wed Jun 19 14:49:35 2024 +0200 +++ b/mercurial/bundlerepo.py Wed Sep 18 17:50:57 2024 -0400 @@ -16,6 +16,7 @@ import contextlib import os import shutil +import typing from .i18n import _ from .node import ( @@ -287,7 +288,13 @@ return filespos -class bundlerepository: +_bundle_repo_baseclass = object + +if typing.TYPE_CHECKING: + _bundle_repo_baseclass = localrepo.localrepository + + +class bundlerepository(_bundle_repo_baseclass): """A repository instance that is a union of a local repo and a bundle. Instances represent a read-only repository composed of a local repository