# HG changeset patch # User Matt Harbison # Date 1727388271 14400 # Node ID 382d9629cede6e8df29e650da5e3086ea2fc66a0 # Parent ef7d85089952add5b1734a9ef65e0b2e074cd34b interfaces: convert the dirstate zope interface to a Protocol class This is a small trial run for converting the repository interfaces enmasse, in the same series of steps. I'm not sure that this current code is valid (it has zope attribute fields, and it's missing all of the `self` args on its functions, but that was the previous state of things, and made PyCharm really unhappy). But it will be easier to review the repository interface changes if this change is separate from adding `self` and dropping the zope attributes all over. Having an empty constructor in a protocol is weird. I'm not sure if these args should be converted to fields that all subclasses would have, and comments around existing attributes say some should be going away. Comment it out for now so that it's not in the way, but also not forgotten. diff -r ef7d85089952 -r 382d9629cede mercurial/interfaces/dirstate.py --- a/mercurial/interfaces/dirstate.py Thu Sep 26 17:47:39 2024 -0400 +++ b/mercurial/interfaces/dirstate.py Thu Sep 26 18:04:31 2024 -0400 @@ -2,26 +2,32 @@ import contextlib +from typing import ( + Protocol, +) + from . import util as interfaceutil -class idirstate(interfaceutil.Interface): - def __init__( - opener, - ui, - root, - validate, - sparsematchfn, - nodeconstants, - use_dirstate_v2, - use_tracked_hint=False, - ): - """Create a new dirstate object. - - opener is an open()-like callable that can be used to open the - dirstate file; root is the root of the directory tracked by - the dirstate. - """ +class idirstate(Protocol): + # TODO: convert these constructor args to fields? + # def __init__( + # self, + # opener, + # ui, + # root, + # validate, + # sparsematchfn, + # nodeconstants, + # use_dirstate_v2, + # use_tracked_hint=False, + # ): + # """Create a new dirstate object. + # + # opener is an open()-like callable that can be used to open the + # dirstate file; root is the root of the directory tracked by + # the dirstate. + # """ # TODO: all these private methods and attributes should be made # public or removed from the interface.