Comments (9)
os.path.join
in Linux is actuallyposixpath.join
which one do you want? That's not clear for me.
from jedi.
I want os.path.join
instead of posixpath.join
, as posixpath
functions are not in the document.
from jedi.
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.
What do you think? I just added your example, please add other files as well!
from jedi.
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.
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.
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.
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.
Thanks! I will add mappings when I find some. Hope that there are not too many.
from jedi.
Related Issues (20)
- kwargs forwarding? HOT 1
- `LazyKnownValues` has no attribute `string_name`? HOT 4
- Enum name auto-completion without parentheses HOT 1
- Jedi searches the python interpreter in the wrong path. HOT 8
- Unhandled Exception with Unnamed Lambdas When Analyzing References Using dynaconf
- Add support for async pytest fixtures
- Is it possible to generate completion for `argparse.Namespace`? HOT 5
- TypedDict : Suggestion issues HOT 2
- Python stubs loaded from extensions folder even when using an explicit interpreter HOT 8
- Error when trying to detect environment HOT 5
- `PathFinder` has no attribute `find_module` in `python 12.2` HOT 2
- Questions about Copilot + Open Source Software Hierarchy HOT 1
- What exactly does "smart_sys_path" do? HOT 5
- Completion fails when variable name is identical to type name HOT 4
- 'TreeInstance' object has no attribute 'with_generics' when using typing.Literal["str"] return annotation on property HOT 4
- How to discover the import statement for a particular Name? HOT 4
- Does Jedi support type inference for type annotations that include generics? HOT 2
- _get_executable_path() can't get the correct path on Windows Anaconda
- Issues with pytest 8 HOT 1
- [Feature request] Support for syntax coloring (based on symbol type) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jedi.