This is an archive of the discontinued Mercurial Phabricator instance.

py3: manually import pycompat.open into files that need it
ClosedPublic

Authored by indygreg on Oct 6 2019, 5:22 PM.

Details

Summary

We want to eliminate the source transformer. Currently it inserts
a from mercurial.pycompat import ... at the top of files to alias
some builtins.

This commit replaces the implicit import of open with an explicit
import on files that need it and changes the source transformer to
no longer import open.

As part of this, we needed to store an explicit local for open in
the Python 2 code path in pycompat so the import works. (Builtins
that are automatically in scope cannot be imported.)

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

indygreg created this revision.Oct 6 2019, 5:22 PM

Can we import io.open regardless of Python version instead?

Can we import io.open regardless of Python version instead?

That won't work because pycompat.open accepts bytestrings as the mode argument. I'll take this now, and then we can do a cleanup to unwind the mode string back to a sysstr everywhere (I'll take that on if Pulkit doesn't).

This revision was not accepted when it landed; it landed in state Needs Review.
This revision was automatically updated to reflect the committed changes.