8000 Fix package structure, absolute imports · Issue #9 · endolith/elsim · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Fix package structure, absolute imports #9
Open
@endolith

Description

@endolith

Currently the overall package structure is what I want:

import elsim

elsim.__dir__()
Out[3]: 
[...
 'strategies',
 'elections',
 'methods']

As is the methods sub-package:

elsim.methods.__dir__()
Out[4]: 
[...
 '_common',
 'approval',
 'combined_approval',
 'condorcet',
 'borda',
 'black',
 'condorcet_from_matrix',
 'ranked_election_to_matrix',
 'coombs',
 'fptp',
 'irv',
 'runoff',
 'score',
 'star',
 'utility_winner']

But the other two include cruft that shouldn't be exposed to the user, such as np and cdist, and elections includes itself:

elsim.elections.__dir__()
Out[5]: 
[...
 'elections',
 'numbers',
 'np',
 '
4E06
cdist',
 'honest_rankings',
 'elections_rng',
 'check_random_state',
 'random_utilities',
 'impartial_culture',
 'normal_electorate',
 'normed_dist_utilities']

Also the __init__.py files have relative imports, despite this being mildly recommended against by PEP8:

Absolute imports are recommended, as they are usually more readable and tend to be better behaved (or at least give better error messages) if the import system is incorrectly configured (such as when a directory inside a package ends up on sys.path):

from . import elections, strategies, methods

Though there are a lot of other packages that do it this way.

I've always been confused about the best way to do this stuff.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0