From 5430d156ba2481ac04d193bb448f205c50f2ada0 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sun, 18 Nov 2012 01:02:07 +0100 Subject: [PATCH] added fullname for #61 --- jedi/api_classes.py | 35 ++++++++++++++++++++++++++++------- test/completion/ordering.py | 1 + test/regression.py | 5 +++++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/jedi/api_classes.py b/jedi/api_classes.py index ca96d6e18..8239402d1 100644 --- a/jedi/api_classes.py +++ b/jedi/api_classes.py @@ -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 @@ -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): @@ -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) diff --git a/test/completion/ordering.py b/test/completion/ordering.py index 2ed483fa4..994ec8a86 100644 --- a/test/completion/ordering.py +++ b/test/completion/ordering.py @@ -81,6 +81,7 @@ def func(a_param): #? [] a_param. +from os import path # ----------------- # class # ----------------- diff --git a/test/regression.py b/test/regression.py index 792f87f9b..65e446285 100755 --- a/test/regression.py +++ b/test/regression.py @@ -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