Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shadowed submodule names #44

Open
Technologicat opened this issue Oct 29, 2019 · 3 comments
Open

Fix shadowed submodule names #44

Technologicat opened this issue Oct 29, 2019 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Technologicat
Copy link
Owner

Technologicat commented Oct 29, 2019

Some constructs such as unpythonic.env.env and unpythonic.llist.llist have the same name as the submodule they live in. This hides the submodule from the dict of the top-level namespace of the unpythonic module. This behavior should be considered a bug.

To improve discoverability (e.g. groups of functionality; submodule top-level docstrings), the offending modules should be renamed to avoid becoming shadowed.

It's better to rename the modules than the symbols, since the symbols are certainly used by client code, but the submodule names necessarily aren't. It's not wrong to import directly from a submodule of unpythonic, if that feels more readable at the use site, but it's not mandatory, either, since the top-level __init__ imports all public symbols into the top-level unpythonic namespace. (This behavior is part of the public API, and is not going away.)

This is a breaking change, so we'll wait until the next major version before we do it.

CAUTION: Renaming the modules will break unpickling for instances that were pickled using the old version. [1] says that pickle can save and restore class instances transparently, however the class definition must be importable and live in the same module as when the object was stored. (emphasis mine)

@Technologicat Technologicat added the bug Something isn't working label Oct 29, 2019
@Technologicat Technologicat added this to the 0.15 milestone Oct 29, 2019
@Technologicat Technologicat self-assigned this Oct 29, 2019
@Technologicat
Copy link
Owner Author

This is also an issue because of The submodules are added to the package namespace trap. So if anything, anywhere, imports one of the submodules, the name in the top-level unpythonic namespace will reset to point to the submodule.

@Technologicat
Copy link
Owner Author

Technologicat commented Nov 12, 2019

The trap is also documented in the Python reference, §5.4.2.

Also on SO.

@Technologicat
Copy link
Owner Author

Technologicat commented Dec 4, 2019

New names, list in progress:

  • unpythonic.itunpythonic.itertools, in analogy with standard itertools
  • unpythonic.fununpythonic.functools, similarly
  • unpythonic.llistunpythonic.linkedlists

Maybe:

  • unpythonic.ecunpythonic.escapes
  • unpythonic.fupunpythonic.fpupdate, in analogy with unpythonic.fploop

@Technologicat Technologicat modified the milestones: 0.15, 0.15.x Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant