equal
deleted
inserted
replaced
237 [] |
237 [] |
238 >>> # relative importing |
238 >>> # relative importing |
239 >>> sorted(imported_modules( |
239 >>> sorted(imported_modules( |
240 ... 'import foo1; from bar import bar1', |
240 ... 'import foo1; from bar import bar1', |
241 ... modulename, localmods)) |
241 ... modulename, localmods)) |
242 ['foo.bar.__init__', 'foo.bar.bar1', 'foo.foo1'] |
242 ['foo.bar.bar1', 'foo.foo1'] |
243 >>> sorted(imported_modules( |
243 >>> sorted(imported_modules( |
244 ... 'from bar.bar1 import name1, name2, name3', |
244 ... 'from bar.bar1 import name1, name2, name3', |
245 ... modulename, localmods)) |
245 ... modulename, localmods)) |
246 ['foo.bar.bar1'] |
246 ['foo.bar.bar1'] |
247 >>> # absolute importing |
247 >>> # absolute importing |
284 if not found: |
284 if not found: |
285 # this should import standard library |
285 # this should import standard library |
286 continue |
286 continue |
287 |
287 |
288 absname, dottedpath, hassubmod = found |
288 absname, dottedpath, hassubmod = found |
289 yield dottedpath |
|
290 if not hassubmod: |
289 if not hassubmod: |
|
290 # "dottedpath" is not a package; must be imported |
|
291 yield dottedpath |
291 # examination of "node.names" should be redundant |
292 # examination of "node.names" should be redundant |
292 # e.g.: from mercurial.node import nullid, nullrev |
293 # e.g.: from mercurial.node import nullid, nullrev |
293 continue |
294 continue |
294 |
295 |
|
296 modnotfound = False |
295 prefix = absname + '.' |
297 prefix = absname + '.' |
296 for n in node.names: |
298 for n in node.names: |
297 found = fromlocal(prefix + n.name) |
299 found = fromlocal(prefix + n.name) |
298 if not found: |
300 if not found: |
299 # this should be a function or a property of "node.module" |
301 # this should be a function or a property of "node.module" |
|
302 modnotfound = True |
300 continue |
303 continue |
301 yield found[1] |
304 yield found[1] |
|
305 if modnotfound: |
|
306 # "dottedpath" is a package, but imported because of non-module |
|
307 # lookup |
|
308 yield dottedpath |
302 |
309 |
303 def verify_import_convention(module, source): |
310 def verify_import_convention(module, source): |
304 """Verify imports match our established coding convention. |
311 """Verify imports match our established coding convention. |
305 |
312 |
306 We have 2 conventions: legacy and modern. The modern convention is in |
313 We have 2 conventions: legacy and modern. The modern convention is in |