Code Monkey home page Code Monkey logo

Comments (9)

davidhalter avatar davidhalter commented on July 20, 2024

os.path.join in Linux is actually posixpath.join

which one do you want? That's not clear for me.

from jedi.

tkf avatar tkf commented on July 20, 2024

I want os.path.join instead of posixpath.join, as posixpath functions are not in the document.

from jedi.

davidhalter avatar davidhalter commented on July 20, 2024

All right, I think we have to do that with a mapping for builtin modules. Everything else would be too complicated to implement.

from jedi.

davidhalter avatar davidhalter commented on July 20, 2024

What do you think? I just added your example, please add other files as well!

from jedi.

tkf avatar tkf commented on July 20, 2024

Hi, thanks for the enhancement! When I try full_name on os.path, I got this:

In [2]:
source = """\
import os
os.path"""
lines = source.splitlines()
script = jedi.Script(source, len(lines), len(lines[-1]), None)
definition = script.get_definition()
definition
Out [2]:
[<Definition module genericpath>,
 <Definition module ntpath>,
 <Definition module posixpath>,
 <Definition module genericpath>,
 <Definition module os2emxpath>]

In [3]:
[(d, d.full_name) for d in definition]
Out [3]:
[(<Definition module genericpath>, 'genericpath'),
 (<Definition module ntpath>, 'os.path'),
 (<Definition module posixpath>, 'os.path'),
 (<Definition module genericpath>, 'genericpath'),
 (<Definition module os2emxpath>, 'os.path')]

For my purpose, I want d.full_name to be "os.path", because then I can simply do definition[0].full_name to get full name. Or maybe it is better to have Script.get_full_name(), which returns a string, rather than having Definition.full_name? Having same "full name" for different definitions feels a bit strange (or not?). Sorry, I was not aware of that Script.get_definition might return multiple definitions when I wrote the request, although I already knew that from the other question I asked before.

from jedi.

davidhalter avatar davidhalter commented on July 20, 2024

There won't be another version of this, because there is always a possibility to return two different versions of a path (here it would be genericpath and os.path, I fixed this in the above commit). A script like

if a:
    import foo as path
else:
    from os import path

is always possible. Therefore multiple elements can and should be returned. So I suggest you use this code:

set(d.full_name for d in definition)

if you just want soome element (this would work in the above example). Normally there is only one fullname. If there are multiple fullnames, you have to handle that. I would suggest to let the user choose. If that's not what you want, just take one definition by chance.

from jedi.

tkf avatar tkf commented on July 20, 2024

I see. It makes sense that library user must decide how to pickup the full name.

I tried another example:

In [4]:
source = """\
import argparse
parser = argparse.ArgumentParser()
parser.add_argument"""
lines = source.splitlines()
script = jedi.Script(source, len(lines), len(lines[-1]), None)
definition = script.get_definition()
definition
Out [4]:
[<Definition def add_argument>]

In [5]:
definition[0].full_name
Out [5]:
'argparse._ActionsContainer.add_argument'

I think definition[0].full_name should return argparse.ArgumentParser.add_argument. But I think current implementation of full_name cannot fix this name, right? Perhaps BaseOutput._mapping should be a map from tuple-of-str to str, instead of a map from str to str, so that you can do something like this (untested)?

head = paths[:-1]
tail = [paths[-1]]
# Try to find the longest match in self._mapping:
while head:
    try:
        tail.append(self._mapping[tuple(head)])
        break
    except KeyError:
        pass
    tail.append(head.pop())
return '.'.join(reversed(tail))

from jedi.

davidhalter avatar davidhalter commented on July 20, 2024

I added some code... I didn't do any testing, so please be sure to test it. Also if it fails, just fix it. :-)

from jedi.

tkf avatar tkf commented on July 20, 2024

Thanks! I will add mappings when I find some. Hope that there are not too many.

from jedi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.