Skip to content

Commit

Permalink
added fullname for #61
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Nov 18, 2012
1 parent 4adcc77 commit 5430d15
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
35 changes: 28 additions & 7 deletions jedi/api_classes.py
Expand Up @@ -10,6 +10,13 @@


class BaseOutput(object):
_mapping = {'posixpath': 'os.path',
'riscospath': 'os.path',
'ntpath': 'os.path',
'os2emxpath': 'os.path',
'_io': 'io'
}

def __init__(self, definition, start_pos):
self.start_pos = start_pos
self.definition = definition
Expand All @@ -24,13 +31,14 @@ def __init__(self, definition, start_pos):
# generate a path to the definition
self.module_path = str(definition.get_parent_until().path)
self.path = []
par = definition
while par is not None:
if not par.isinstance(
parsing.Flow, parsing.Statement, parsing.Import,
evaluate.Array, parsing.Name):
self.path.insert(0, par.name)
par = par.parent()
if not isinstance(definition, keywords.Keyword):
par = definition
while par is not None:
if not par.isinstance(
parsing.Flow, parsing.Statement, parsing.Import,
evaluate.Array, parsing.Name):
self.path.insert(0, par.name)
par = par.parent()

@property
def module_name(self):
Expand Down Expand Up @@ -70,6 +78,19 @@ def raw_doc(self):
def description(self):
raise NotImplementedError('Base Class')

@property
def full_name(self):
"""
Returns the path to a certain class/function, see #61.
"""
path = [str(p) for p in self.path]
# TODO add further checks, the mapping should only occur on stdlib.
try:
path[0] = self._mapping[path[0]]
except KeyError:
pass
return '.'.join(path)

def __repr__(self):
return "<%s %s>" % (type(self).__name__, self.description)

Expand Down
1 change: 1 addition & 0 deletions test/completion/ordering.py
Expand Up @@ -81,6 +81,7 @@ def func(a_param):
#? []
a_param.

from os import path
# -----------------
# class
# -----------------
Expand Down
5 changes: 5 additions & 0 deletions test/regression.py
Expand Up @@ -229,6 +229,11 @@ def test_os_nowait(self):
assert 'P_NOWAIT' in [i.word for i in s]


class TestFeature(Base):
def test_full_name(self):
""" feature request #61"""
assert self.complete('import os; os.path.join')[0].full_name == 'os.path.join'

class TestSpeed(Base):
def _check_speed(time_per_run, number=10):
""" Speed checks should typically be very tolerant. Some machines are
Expand Down

0 comments on commit 5430d15

Please sign in to comment.