[Python-Dev] Question on imports and packages

Michael Foord fuzzyman at voidspace.org.uk
Wed Nov 3 02:08:21 CET 2010


On 02/11/2010 23:44, Raymond Hettinger wrote:
> Brett,  Does the import mechanism for importing packages preserve enough information to be able to figure-out where all the components are defined?  I'm wondering if it is possible for the class browser to be built-out to scan/navigate class structure across a module that has been split into a package.

Can it not do that through static analysis - just look at the classes / 
functions defined in the sub-modules. I mean, you could do it from the 
ast, right. Relying on importing code to analyse it is unpleasant if the 
code has top level side-effects (which no good code does of course).

There may be *some* cases where magic makes things weird (__package__), 
but how common are those in practise?

If you build up a data-structure representing definitions in a package, 
working out where any individual class / function used in a module is 
defined is a matter of looking at where it is imported (assuming it 
hasn't been aliased or fetched dynamically) and matching the import to a 
package you have analysed (or analyse on the fly).

A project that attempts to do something like this is pysmell:

http://github.com/orestis/pysmell/

All the best,

Michael

> Raymod
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk


-- 

http://www.voidspace.org.uk/

READ CAREFULLY. By accepting and reading this email you agree,
on behalf of your employer, to release me from all obligations
and waivers arising from any and all NON-NEGOTIATED agreements,
licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap,
confidentiality, non-disclosure, non-compete and acceptable use
policies (”BOGUS AGREEMENTS”) that I have entered into with your
employer, its partners, licensors, agents and assigns, in
perpetuity, without prejudice to my ongoing rights and privileges.
You further represent that you have the authority to release me
from any BOGUS AGREEMENTS on behalf of your employer.



More information about the Python-Dev mailing list