This is an archive of the discontinued Mercurial Phabricator instance.

cbor: add a __init__.py to top level cbor module
ClosedPublic

Authored by pulkit on Mar 9 2018, 5:54 AM.

Details

Summary

This patch also fixes import in cbor2/ to make them relative.

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

pulkit created this revision.Mar 9 2018, 5:54 AM

I think you should send the relative import patches to upstream. Adding from __future__ import absolute_import would also be a nice touch.

I think you should send the relative import patches to upstream. Adding from __future__ import absolute_import would also be a nice touch.

I tried that at https://github.com/agronholm/cbor2/pull/20. I might be doing something wrong here but I am not sure what's that.

In D2752#45926, @pulkit wrote:

I think you should send the relative import patches to upstream. Adding from __future__ import absolute_import would also be a nice touch.

I tried that at https://github.com/agronholm/cbor2/pull/20. I might be doing something wrong here but I am not sure what's that.

I started engaging the package author on that PR. I care enough about this issue that I may start a discussion on a Python mailing list about it. Not sure which one though.

@alex_gaynor: if I wanted to convince some heavy hitters in the Python community that relative imports within packages should be a best practice, how would you recommend going about that?

@alex_gaynor: if I wanted to convince some heavy hitters in the Python community that relative imports within packages should be a best practice, how would you recommend going about that?

The heaviest stick would be to write a PEP encouraging this practice, that way there'd be a canonical place to point people.

An intermediate step might be starting a thread on python-dev (or maybe python-ideas) about it.

You can also always blog about why it's useful. I think best practices around relative imports (explicit and implicit) were formed in a different era and deserve reconsideration.

An intermediate step might be starting a thread on python-dev (or maybe python-ideas) about it.

https://mail.python.org/pipermail/python-dev/2018-March/152446.html

In D2752#45926, @pulkit wrote:

I think you should send the relative import patches to upstream. Adding from __future__ import absolute_import would also be a nice touch.

I tried that at https://github.com/agronholm/cbor2/pull/20. I might be doing something wrong here but I am not sure what's that.

The relative imports are now done: https://github.com/agronholm/cbor2/commit/84181540f6eb650437e3f73cd104a65661fe8e67

indygreg accepted this revision.Mar 26 2018, 11:34 AM

I vendored upstream commit 84181540f6eb650437e3f73cd104a65661fe8e67. So the relative imports will drop from this commit when it is pushed.

This revision is now accepted and ready to land.Mar 26 2018, 11:34 AM
This revision was automatically updated to reflect the committed changes.

I also fixed this in flight to make the import in __init__.py relative.