1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
# -----------------
# own structure
# -----------------
# do separate scopes
def scope_basic():
from import_tree import mod1
#? int()
mod1.a
#? []
import_tree.a
#? []
import_tree.mod1
import import_tree
#? str()
import_tree.a
def scope_pkg():
import import_tree.mod1
#? str()
import_tree.a
#? ['mod1']
import_tree.mod1
#? int()
import_tree.mod1.a
def scope_nested():
import import_tree.pkg.mod1
#? str()
import_tree.a
#? list
import_tree.pkg.a
#? ['sqrt']
import_tree.pkg.sqrt
#? ['pkg']
import_tree.p
#? float()
import_tree.pkg.mod1.a
#? ['a', '__name__', '__package__', '__file__', '__doc__']
a = import_tree.pkg.mod1.
import import_tree.random
#? set
import_tree.random.a
def scope_nested2():
"""Multiple modules should be indexable, if imported"""
import import_tree.mod1
import import_tree.pkg
#? ['mod1']
import_tree.mod1
#? ['pkg']
import_tree.pkg
# With the latest changes this completion also works, because submodules
# are always included (some nested import structures lead to this,
# typically).
#? ['rename1']
import_tree.rename1
def scope_from_import_variable():
"""
All of them shouldn't work, because "fake" imports don't work in python
without the use of ``sys.modules`` modifications (e.g. ``os.path`` see also
github issue #213 for clarification.
"""
a = 3
#?
from import_tree.mod2.fake import a
#?
from import_tree.mod2.fake import c
#?
a
#?
c
def scope_from_import_variable_with_parenthesis():
from import_tree.mod2.fake import (
a, foobarbaz
)
#?
a
#?
foobarbaz
# shouldn't complete, should still list the name though.
#? ['foobarbaz']
foobarbaz
def as_imports():
from import_tree.mod1 import a as xyz
#? int()
xyz
import not_existant, import_tree.mod1 as foo
#? int()
foo.a
import import_tree.mod1 as bar
#? int()
bar.a
def test_import_priorities():
"""
It's possible to overwrite import paths in an ``__init__.py`` file, by
just assigining something there.
See also #536.
"""
from import_tree import the_pkg, invisible_pkg
#? int()
invisible_pkg
# In real Python, this would be the module, but it's not, because Jedi
# doesn't care about most stateful issues such as __dict__, which it would
# need to, to do this in a correct way.
#? int()
the_pkg
# Importing foo is still possible, even though inivisible_pkg got changed.
#? float()
from import_tree.invisible_pkg import foo
# -----------------
# std lib modules
# -----------------
import tokenize
#? ['tok_name']
tokenize.tok_name
from pyclbr import *
#? ['readmodule_ex']
readmodule_ex
import os
#? ['dirname']
os.path.dirname
from os.path import (
expanduser
)
#? os.path.expanduser
expanduser
from itertools import (tee,
islice)
#? ['islice']
islice
from functools import (partial, wraps)
#? ['wraps']
wraps
from keyword import kwlist, \
iskeyword
#? ['kwlist']
kwlist
#? []
from keyword import not_existing1, not_existing2
from tokenize import io
tokenize.generate_tokens
# -----------------
# builtins
# -----------------
import sys
#? ['prefix']
sys.prefix
#? ['append']
sys.path.append
from math import *
#? ['cos', 'cosh']
cos
def func_with_import():
import time
return time
#? ['sleep']
func_with_import().sleep
# -----------------
# relative imports
# -----------------
from .import_tree import mod1
#? int()
mod1.a
from ..import_tree import mod1
#?
mod1.a
from .......import_tree import mod1
#?
mod1.a
from .. import helpers
#? int()
helpers.sample_int
from ..helpers import sample_int as f
#? int()
f
from . import run
#? []
run.
from . import import_tree as imp_tree
#? str()
imp_tree.a
from . import datetime as mod1
#? []
mod1.
# self import
# this can cause recursions
from imports import *
# -----------------
# packages
# -----------------
from import_tree.mod1 import c
#? set
c
from import_tree import recurse_class1
#? ['a']
recurse_class1.C.a
# github #239 RecursionError
#? ['a']
recurse_class1.C().a
# -----------------
# Jedi debugging
# -----------------
# memoizing issues (check git history for the fix)
import not_existing_import
if not_existing_import:
a = not_existing_import
else:
a = not_existing_import
#?
a
# -----------------
# module underscore descriptors
# -----------------
def underscore():
import keyword
#? ['__file__']
keyword.__file__
#? str()
keyword.__file__
# Does that also work for the our own module?
#? ['__file__']
__file__
|