Skip to content
Snippets Groups Projects
Commit a3967dbac7be authored by Matt Harbison's avatar Matt Harbison
Browse files

typing: replace `localrepo` import in `phases` module with protocol class

This likely breaks a pytype cycle, but also pytype 2024.10.11 is getting smarter,
and was able to sniff out some possible return types on `localrepo.__getitem__()`
that would cause problems (if they were true):

        /home/mharbison/projects/mercurial/mercurial-devel/mercurial/phases.py:491:42:
            error: in _addwdir: No attribute 'phase' on list [attribute-error]
          In Optional[Union[list, mercurial.context.changectx, mercurial.context.workingctx]]

                    if wdirrev in wdirsubset and repo[None].phase() in phases:
                                                 ~~~~~~~~~~~~~~~~

        /home/mharbison/projects/mercurial/mercurial-devel/mercurial/phases.py:491:42:
            error: in _addwdir: No attribute 'phase' on None [attribute-error]
          In Optional[Union[list, mercurial.context.changectx, mercurial.context.workingctx]]

                    if wdirrev in wdirsubset and repo[None].phase() in phases:
                                                 ~~~~~~~~~~~~~~~~

        /home/mharbison/projects/mercurial/mercurial-devel/mercurial/phases.py:1098:24:
            error: in pushphase: No attribute 'phase' on list [attribute-error]
          In Union[bytes, list, mercurial.context.changectx, mercurial.context.workingctx]

                currentphase = repo[nhex].phase()
                               ~~~~~~~~~~~~~~~~

        /home/mharbison/projects/mercurial/mercurial-devel/mercurial/phases.py:1098:24:
            error: in pushphase: No attribute 'phase' on bytes [attribute-error]
          In Union[bytes, list, mercurial.context.changectx, mercurial.context.workingctx]

                currentphase = repo[nhex].phase()
                               ~~~~~~~~~~~~~~~~

We probably need some `@overload` on the repo class and the protocol, but settle
for using the (non-typed) interface for now.  This trips over the usage of the
private `_phasecache` attribute, but I'm not sure how to deal with this, so it's
declared on the interface for now.
parent d23188f6874c
No related tags found
1 merge request!1258Draft: typing: replace `localrepo` import in `phases` module with protocol class
Pipeline #99605 skipped
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment