Skip to content

Commit

Permalink
Add method to generate also tags for __builtins__
Browse files Browse the repository at this point in the history
This way we get easily also tags for standard exceptions and a few builtin types.
  • Loading branch information
eht16 committed Aug 29, 2012
1 parent 29f0d02 commit 883ce3a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion scripts/create_py_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def _add_tag(self, obj, tag_type, parent=''):
args = '(%s)' % parent
else:
scope = '%s%s' % (TA_SCOPE, parent)
tagname = obj.__name__
if isinstance(obj, basestring):
tagname = obj
else:
tagname = obj.__name__
# check for duplicates
if len(tagname) < 4:
# skip short tags
Expand Down Expand Up @@ -207,6 +210,22 @@ def process_file(self, filename):
self.tags[tagname] = tag
filep.close()

#----------------------------------------------------------------------
def add_builtins(self):
"""
Add the contents of __builtins__ as simple tags
"""
for tag_name in dir(__builtins__):
# check if the tag name starts with upper case, then we assume it is a class
# note that this is a very very simple heuristic to determine the type and will give
# false positives
if tag_name[0].isupper():
tag_type = TYPE_CLASS
else:
tag_type = TYPE_FUNCTION

self._add_tag(tag_name, tag_type)

#----------------------------------------------------------------------
def write_to_file(self, filename):
"""
Expand Down Expand Up @@ -266,6 +285,7 @@ def main():
args = get_module_filenames(PYTHON_LIB_DIRECTORY)

parser = Parser()
parser.add_builtins()

for filename in args:
parser.process_file(filename)
Expand Down

0 comments on commit 883ce3a

Please sign in to comment.