made code slightly more pytho2 friendly

This commit is contained in:
Claude
2015-12-30 20:00:08 +01:00
parent 90c4ca8c04
commit 67cbc5ebd1
4 changed files with 83 additions and 73 deletions

View File

@@ -3,7 +3,11 @@ This module is not intended to be used in jedi, rather it will be fed to the
jedi-parser to replace classes in the typing module
"""
from collections import abc
try:
from collections import abc
except ImportError:
# python 2
import collections as abc
def factory(typing_name, indextype):

View File

@@ -56,7 +56,7 @@ def _fix_forward_reference(evaluator, item, module):
element.parent = module
return evaluator.eval_element(element)
else:
return {item}
return set([item])
@memoize_default(None, evaluator_is_first_arg=True)
@@ -95,7 +95,7 @@ def get_types_for_typing_module(evaluator, typ, trailer):
# actually the PEP-0484 typing module and not some other
indextypes = evaluator.eval_element(trailer.children[1])
if not isinstance(indextypes, set):
indextypes = {indextypes}
indextypes = set([indextypes])
module = trailer.get_parent_until()
dereferencedindextypes = set()
@@ -109,9 +109,9 @@ def get_types_for_typing_module(evaluator, typ, trailer):
factory = list(factories)[0]
assert factory
function_body_nodes = factory.children[4].children
valid_classnames = {child.name.value
for child in function_body_nodes
if isinstance(child, tree.Class)}
valid_classnames = set(child.name.value
for child in function_body_nodes
if isinstance(child, tree.Class))
if typ.name.value not in valid_classnames:
return None
compiled_classname = compiled.create(evaluator, typ.name.value)

View File

@@ -157,70 +157,3 @@ Y = int
def just_because_we_can(x: "flo" + "at"):
#? float()
x
import typing
def we_can_has_sequence(
p: typing.Sequence[int],
q: typing.Sequence[B],
r: "typing.Sequence[int]",
s: typing.Sequence["int"],
t: typing.MutableSequence[dict],
u: typing.List[float]):
#? ["count"]
p.c
#? int()
p[1]
#? ["count"]
q.c
#? B()
q[1]
#? ["count"]
r.c
#? int()
r[1]
#? ["count"]
s.c
#? int()
s[1]
#? []
s.a
#? ["append"]
t.a
#? dict()
t[1]
#? ["append"]
u.a
#? float()
u[1]
def iterators(
ps: typing.Iterable[int],
qs: typing.Iterator[str],
rs: typing.Sequence["B"],
ts: typing.AbstractSet["float"]):
for p in ps:
#? int()
p
#?
next(ps)
for q in qs:
#? str()
q
#? str()
next(qs)
for r in rs:
#? B()
r
#?
next(rs)
for t in ts:
#? float()
t
def sets(
p: typing.AbstractSet[int],
q: typing.MutableSet[float]):
#? []
p.a
#? ["add"]
q.a

View File

@@ -0,0 +1,73 @@
# python >= 3.2
import typing
class B:
pass
def we_can_has_sequence(
p: typing.Sequence[int],
q: typing.Sequence[B],
r: "typing.Sequence[int]",
s: typing.Sequence["int"],
t: typing.MutableSequence[dict],
u: typing.List[float]):
#? ["count"]
p.c
#? int()
p[1]
#? ["count"]
q.c
#? B()
q[1]
#? ["count"]
r.c
#? int()
r[1]
#? ["count"]
s.c
#? int()
s[1]
#? []
s.a
#? ["append"]
t.a
#? dict()
t[1]
#? ["append"]
u.a
#? float()
u[1]
def iterators(
ps: typing.Iterable[int],
qs: typing.Iterator[str],
rs: typing.Sequence["ForwardReference"],
ts: typing.AbstractSet["float"]):
for p in ps:
#? int()
p
#?
next(ps)
for q in qs:
#? str()
q
#? str()
next(qs)
for r in rs:
#? ForwardReference()
r
#?
next(rs)
for t in ts:
#? float()
t
def sets(
p: typing.AbstractSet[int],
q: typing.MutableSet[float]):
#? []
p.a
#? ["add"]
q.a
class ForwardReference:
pass