Skip to content

Fix shadowed submodule names #44

Open

Description

@Technologicat

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)

Activity

  1. added
    bug
    on Oct 29, 2019
  2. added this to the 0.15 milestone on Oct 29, 2019
  3. Technologicat commented on Oct 31, 2019

    @Technologicat
    OwnerAuthor

    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.

  4. Technologicat commented on Nov 12, 2019

    @Technologicat
    OwnerAuthor

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

    Also on SO.

  5. Technologicat commented on Dec 4, 2019

    @Technologicat
    OwnerAuthor

    New names, list in progress:

    • unpythonic.it → unpythonic.itertools, in analogy with standard itertools
    • unpythonic.fun → unpythonic.functools, similarly
    • unpythonic.llist → unpythonic.linkedlists

    Maybe:

    • unpythonic.ec → unpythonic.escapes
    • unpythonic.fup → unpythonic.fpupdate, in analogy with unpythonic.fploop
  6. modified the milestones: 0.15, 0.15.x on Dec 1, 2020
  7. modified the milestones: 1.x, 3.0.0 on Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions