( )⚙ D6641 py3: source-transform only call-sites of iteritems(), not definitions

This is an archive of the discontinued Mercurial Phabricator instance.

py3: source-transform only call-sites of iteritems(), not definitions
ClosedPublic

Authored by martinvonz on Jul 13 2019, 3:11 AM.

Details

Summary

branchmap.branchcache, among other classes, defines a
iteritems(). That currently gets replaced by items() by the source
transformer. That makes it harder for extensions to work with both py2
and py3, since they have to call either items() or iteritems() on
branchcache. Let's not replace definitions of iteritems() (and
itervalues()) and only replace the call-sites. We need to also add an
items() alias to branchcache (etc) so our transformer call-sites will
find it.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

martinvonz created this revision.Jul 13 2019, 3:11 AM
pulkit accepted this revision.Jul 15 2019, 9:33 AM
This revision is now accepted and ready to land.Jul 15 2019, 9:33 AM
yuja added a subscriber: yuja.Jul 15 2019, 7:39 PM
  • a/mercurial/__init__.py

+++ b/mercurial/__init__.py
@@ -225,7 +225,9 @@

    1. It changes iteritems/values to items/values as they are not
    2. present in Python 3 world.
  • elif fn in ('iteritems', 'itervalues'):

+ elif (fn in ('iteritems', 'itervalues') and
+ not (tokens[i - 1].type == token.NAME and
+ tokens[i - 1].string == 'def')):

Perhaps, we need to bump the BYTECODEHEADER version to recompile all
py3 modules.

In D6641#97205, @yuja wrote:
  • a/mercurial/__init__.py

+++ b/mercurial/__init__.py
@@ -225,7 +225,9 @@

    1. It changes iteritems/values to items/values as they are not
    2. present in Python 3 world.
  • elif fn in ('iteritems', 'itervalues'):

+ elif (fn in ('iteritems', 'itervalues') and
+ not (tokens[i - 1].type == token.NAME and
+ tokens[i - 1].string == 'def')):

Perhaps, we need to bump the BYTECODEHEADER version to recompile all
py3 modules.

Oops, I missed that despite the the big all-caps message. Thanks for pointing that out. I'll fix it in flight (changing HG\x00\x0b to HG\x00\x0c).