Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0688436

Browse files
committed
Enhancements by Sjoerd Mullender: support for
from a.b import c import a . b
1 parent 7a840e8 commit 0688436

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

Lib/pyclbr.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
import re
3939
import string
4040

41-
id = '(?P<id>[A-Za-z_][A-Za-z0-9_]*)' # match identifier
41+
id = '[A-Za-z_][A-Za-z0-9_]*' # match identifier
4242
blank_line = re.compile('^[ \t]*($|#)')
43-
is_class = re.compile('^class[ \t]+'+id+'[ \t]*(?P<sup>\([^)]*\))?[ \t]*:')
44-
is_method = re.compile('^[ \t]+def[ \t]+'+id+'[ \t]*\(')
43+
is_class = re.compile('^class[ \t]+(?P<id>'+id+')[ \t]*(?P<sup>\([^)]*\))?[ \t]*:')
44+
is_method = re.compile('^[ \t]+def[ \t]+(?P<id>'+id+')[ \t]*\(')
4545
is_import = re.compile('^import[ \t]*(?P<imp>[^#]+)')
46-
is_from = re.compile('^from[ \t]+'+id+'[ \t]+import[ \t]+(?P<imp>[^#]+)')
46+
is_from = re.compile('^from[ \t]+(?P<module>'+id+'([ \t]*\\.[ \t]*'+id+')*)[ \t]+import[ \t]+(?P<imp>[^#]+)')
4747
dedent = re.compile('^[^ \t]')
4848
indent = re.compile('^[^ \t]*')
4949

@@ -75,8 +75,8 @@ def readmodule(module, path=[], inpackage=0):
7575
i = string.rfind(module, '.')
7676
if i >= 0:
7777
# Dotted module name
78-
package = module[:i]
79-
submodule = module[i+1:]
78+
package = string.strip(module[:i])
79+
submodule = string.strip(module[i+1:])
8080
parent = readmodule(package, path, inpackage)
8181
child = readmodule(submodule, parent['__path__'], 1)
8282
return child
@@ -146,7 +146,7 @@ def readmodule(module, path=[], inpackage=0):
146146
res = is_from.match(line)
147147
if res:
148148
# from module import stuff
149-
mod = res.group('id')
149+
mod = res.group('module')
150150
names = string.splitfields(res.group('imp'), ',')
151151
try:
152152
# recursively read the imported module

0 commit comments

Comments
 (0)