This is an archive of the discontinued Mercurial Phabricator instance.

import-checker: allow direct symbol import if the symbol is a module
AbandonedPublic

Authored by quark on Aug 28 2017, 9:06 PM.

Details

Reviewers
yuja
Group Reviewers
hg-reviewers
Summary

This would make the checker more friendly for 3rd-party code. For example,

In remotefilelog/x.py, it may have:

from . import shallowutils

This triggers "direct symbol import shallowutils from remotefilelog" today.
Since "shallowutils" itself is a module, the import should be allowed. This
patch makes it so.

It seems the warning is mainly to avoid the situation where other code could
wrap some symbols (typically by extensions.wrapfunction) after import, and
the existing code would still be using old symbols. But it's rare to have
an entire module replaced. So I think this change is reasonable.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

quark created this revision.Aug 28 2017, 9:06 PM
yuja requested changes to this revision.Aug 31 2017, 10:30 AM
yuja added a subscriber: yuja.

In remotefilelog/x.py, it may have:

from . import shallowutils

This triggers "direct symbol import shallowutils from remotefilelog" today.

Perhaps you didn't pass remotefilelog/__init__.py and remotefilelog/shallowutils.py
to import-checker.py. If they are counted as local modules, the error should disappear.

tests/test-imports-checker.t
134

This has to be updated to actually test the "direct symbol import".

This revision now requires changes to proceed.Aug 31 2017, 10:30 AM
quark abandoned this revision.Aug 31 2017, 5:36 PM

You're right. I checked the output again and it worked as expected. I think it was caused by me experimenting with stuff and modified localmods with .__init__ removed (which never got sent). I'll drop this patch. The next patch is still relevant.