This is an archive of the discontinued Mercurial Phabricator instance.

pycompat: add return type annotations
Needs RevisionPublic

Authored by indygreg on Mar 9 2022, 8:07 PM.

Details

Reviewers
Alphare
Group Reviewers
hg-reviewers
Summary

Now that we're using Python 3.6+, we can start using inline type
annotations.

I figured a good a place as any to start would be pycompat. So this
commit defines type annotations throughout the file.

Because we can't use deferred annotations parsing (since this feature
requires Python 3.7), complex types relying on symbols from the typing
module use quoted expressions. This achieves some of the benefit of
deferred parsing without compromising the ability for type checkers to
infer things.

When annotating open() as part of this change, pytype started
complaining about a type mismatch in profiling.py. This turned out
to be a false positive. So the error was suppressed.

Diff Detail

Repository
rHG Mercurial
Branch
default
Lint
No Linters Available
Unit
No Unit Test Coverage

Event Timeline

indygreg created this revision.Mar 9 2022, 8:07 PM
Alphare requested changes to this revision.Mar 14 2022, 6:15 AM
Alphare added a subscriber: Alphare.
Alphare added inline comments.
mercurial/profiling.py
275

I think we should instead add an assert that self._fp is the right type, which would satisfy Pytype without disabling it and be more regression-proof.

This revision now requires changes to proceed.Mar 14 2022, 6:15 AM