This page tries to summarize the results of the discussion on sage-devel I formulate everything here as strict rules, but of course every guideline can have a valid use case for not following it, but stating things in a political correct way would just obfuscate the main ideas.

Possible Guide Lines

Use relative imports


Opinion on sage-dev

Mixed, most think it is not a good idea.

Pros

Cons

Don't import specific functions or classes from another module


opinion on sage-dev

To early to tell.

Pros

Cons

import sage.rings.all

will force 4? lookups at runtime when later executing

sage.rings.all.ZZ(3)

while

from sage.rings.all import ZZ

will cause 1? lookup at runtime when later executing

ZZ(3)

Solutions to concrete problems

To be provided

Examples

bad: import module.a.b.c.d  #slow at runtime

good: from module.a.b.c import d

bad:

from module.sub_module import some_function #cause of problems with possible circular imports

from module.sub_module import some_class #cause of problems with possible circular imports

good:

from module.sub_module import some_sub_sub_module

import module

valid use case to ignore this guideline: To be provided

Links/Resources

import (last edited 2022-04-25 04:05:57 by mkoeppe)