##// END OF EJS Templates
interfaces: convert `repository.ipeerconnection` from zope `Attribute` attrs...
interfaces: convert `repository.ipeerconnection` from zope `Attribute` attrs This is the same transformation as b455dfddfed0 did for dirstate. Since type annotations are wrapped up in this transformation (the file syntax is such that *some* type needs to be declared, even if `Any`), this can be done piecemeal. See that commit for more background detail. Initially, I imported `uimod` here, delayed to the type checking phase, like a bunch of other modules are currently doing. That caused a problem with pytype no longer inferring types in some seemingly unrelated modules, which was also mentioned in a1c0f19e7cb4. None of the following applies to this commit, because dropping the import and aliasing `Ui = Any` until we get a Protocol class in place avoids this issue. But for posterity, the exact problem was that pytype 2023.11.21 on Python 3.10.11 stopped inferring the (currently undeclared) `int` type of the following attributes in `mercurial.revlog`, switching them to `Any`. - COMP_MODE_INLINE - REVIDX_DEFAULT_FLAGS - REVIDX_ELLIPSIS - REVIDX_EXTSTORED - REVIDX_FLAGS_ORDER - REVIDX_HASCOPIESINFO - REVIDX_ISCENSORED - REVIDX_RAWTEXT_CHANGING_FLAGS That had cascading effects on `hgext.remotefilelog.shallowutil`, `mercurial.metadata`, and `mercurial.pure.parsers`, mostly on return types it was no longer able to infer. These fields above are imported directly through a couple of `mercurial.revlogutils` modules. Unfortunately, explicitly typing those original fields only preserved the type for `COMP_MODE_INLINE`. The only difference I see is this field is defined in `mercurial/revlogutils/__init__.py`, and the rest are defined in `mercurial/revlogutils/constants.py`, but I don't know the significance of that. The `mercurial/revlogutils/*.pyi` files have the correct type with or without the explicit typing when the import is present- it's only the `revlog` module's imports that seem to be affected. And since they are direct imports, there's no way that I know of to assign a type, like there would be if there was a field assignment. There is an import cycle of sorts here when importing ui, that is likely the problem: interfaces.repository -> ui -> utils.urlutil -> revlogutils.constants -> interfaces.repository Running `ls -gGrt --time-style=full` on the associated *.pyi files that get generated showed that `revlog.pyi` was created before the `revlogutils` files. I tried moving the import of `utils.urlutil` in `mercurial.ui` into `ui.paths()` instead of a top level import, and that didn't help. It could be argued that `ui.pyi` would need the import anyway because `ui.paths()` returns an instance of `utils.urlutil.paths`, but pytype is currently typing that as `Any`, because it gets confused by the `@util.propertycache` decorator (replacing that with `Any`), and it dropped the import of `utils.urlutil` as expected with that change. I'm a little skeptical that cycle is a problem though, because `interfaces.repository` also started importing `utils.urlutil` here, which means there's this cycle that's not a problem: interfaces.repository -> utils.urlutil -> revlogutils.constants -> interfaces.repository PyCharm is also able to sniff out the types in `mercurial.revlog` with the import, so I'm not sure if this is a bug/limitation in pytype, or what.
Matt Harbison -
r53360:0cfcc276 default
Show More
Name Size Modified Last Commit Author
/ mercurial / templates / atom
__init__.py Loading ...
bookmarkentry.tmpl Loading ...
bookmarks.tmpl Loading ...
branchentry.tmpl Loading ...
branches.tmpl Loading ...
changelog.tmpl Loading ...
changelogentry.tmpl Loading ...
error.tmpl Loading ...
filelog.tmpl Loading ...
header.tmpl Loading ...
map Loading ...
tagentry.tmpl Loading ...
tags.tmpl Loading ...