adding new stuff

This commit is contained in:
ViktorBarzin 2017-07-09 00:22:01 +03:00
parent f84d7183aa
commit 9ef8a96f9a
1580 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,73 @@
# -----------------
# normal arguments (no keywords)
# -----------------
def simple(a):
return a
simple(1)
#! 6 type-error-too-few-arguments
simple()
#! 10 type-error-too-many-arguments
simple(1, 2)
#! 10 type-error-too-many-arguments
simple(1, 2, 3)
# -----------------
# keyword arguments
# -----------------
simple(a=1)
#! 7 type-error-keyword-argument
simple(b=1)
#! 10 type-error-too-many-arguments
simple(1, a=1)
def two_params(x, y):
return y
two_params(y=2, x=1)
two_params(1, y=2)
#! 11 type-error-multiple-values
two_params(1, x=2)
#! 17 type-error-too-many-arguments
two_params(1, 2, y=3)
# -----------------
# default arguments
# -----------------
def default(x, y=1, z=2):
return x
#! 7 type-error-too-few-arguments
default()
default(1)
default(1, 2)
default(1, 2, 3)
#! 17 type-error-too-many-arguments
default(1, 2, 3, 4)
default(x=1)
# -----------------
# class arguments
# -----------------
class Instance():
def __init__(self, foo):
self.foo = foo
Instance(1).foo
Instance(foo=1).foo
#! 12 type-error-too-many-arguments
Instance(1, 2).foo
#! 8 type-error-too-few-arguments
Instance().foo

View file

@ -0,0 +1,119 @@
class Cls():
class_attr = ''
def __init__(self, input):
self.instance_attr = 3
self.input = input
def f(self):
#! 12 attribute-error
return self.not_existing
def undefined_object(self, obj):
"""
Uses an arbitrary object and performs an operation on it, shouldn't
be a problem.
"""
obj.arbitrary_lookup
def defined_lookup(self, obj):
"""
`obj` is defined by a call into this function.
"""
obj.upper
#! 4 attribute-error
obj.arbitrary_lookup
#! 13 name-error
class_attr = a
Cls(1).defined_lookup('')
c = Cls(1)
c.class_attr
Cls.class_attr
#! 4 attribute-error
Cls.class_attr_error
c.instance_attr
#! 2 attribute-error
c.instance_attr_error
c.something = None
#! 12 name-error
something = a
something
# -----------------
# Unused array variables should still raise attribute errors.
# -----------------
# should not raise anything.
for loop_variable in [1, 2]:
#! 4 name-error
x = undefined
loop_variable
#! 28 name-error
for loop_variable in [1, 2, undefined]:
pass
#! 7 attribute-error
[1, ''.undefined_attr]
def return_one(something):
return 1
#! 14 attribute-error
return_one(''.undefined_attribute)
#! 12 name-error
[r for r in undefined]
#! 1 name-error
[undefined for r in [1, 2]]
[r for r in [1, 2]]
# some random error that showed up
class NotCalled():
def match_something(self, param):
seems_to_need_an_assignment = param
return [value.match_something() for value in []]
# -----------------
# decorators
# -----------------
#! 1 name-error
@undefined_decorator
def func():
return 1
# -----------------
# operators
# -----------------
string = '%s %s' % (1, 2)
# Shouldn't raise an error, because `string` is really just a string, not an
# array or something.
string.upper
# -----------------
# imports
# -----------------
# Star imports and the like in modules should not cause attribute errors in
# this module.
import import_tree
import_tree.a
import_tree.b
# This is something that raised an error, because it was using a complex
# mixture of Jedi fakes and compiled objects.
import _sre
#! 15 attribute-error
_sre.compile().not_existing

View file

@ -0,0 +1,46 @@
"""
Jedi issues warnings for possible errors if ``__getattr__``,
``__getattribute__`` or ``setattr`` are used.
"""
# -----------------
# __getattr*__
# -----------------
class Cls():
def __getattr__(self, name):
return getattr(str, name)
Cls().upper
#! 6 warning attribute-error
Cls().undefined
class Inherited(Cls):
pass
Inherited().upper
#! 12 warning attribute-error
Inherited().undefined
# -----------------
# setattr
# -----------------
class SetattrCls():
def __init__(self, dct):
# Jedi doesn't even try to understand such code
for k, v in dct.items():
setattr(self, k, v)
self.defined = 3
c = SetattrCls({'a': 'b'})
c.defined
#! 2 warning attribute-error
c.undefined

View file

@ -0,0 +1,46 @@
# -----------------
# Simple tests
# -----------------
import random
if random.choice([0, 1]):
x = ''
else:
x = 1
if random.choice([0, 1]):
y = ''
else:
y = 1
# A simple test
if x != 1:
x.upper()
else:
#! 2 attribute-error
x.upper()
pass
# This operation is wrong, because the types could be different.
#! 6 type-error-operation
z = x + y
# However, here we have correct types.
if x == y:
z = x + y
else:
#! 6 type-error-operation
z = x + y
# -----------------
# With a function
# -----------------
def addition(a, b):
if type(a) == type(b):
return a + b
else:
#! 9 type-error-operation
return a + b
addition(1, 1)
addition(1.0, '')

View file

@ -0,0 +1,11 @@
# ----------
# isinstance
# ----------
isinstance(1, int)
isinstance(1, (int, str))
#! 14 type-error-isinstance
isinstance(1, 1)
#! 14 type-error-isinstance
isinstance(1, [int, str])

View file

@ -0,0 +1,13 @@
class Base(object):
class Nested():
def foo():
pass
class X(Base.Nested):
pass
X().foo()
#! 4 attribute-error
X().bar()

View file

@ -0,0 +1,41 @@
[a + 1 for a in [1, 2]]
#! 3 type-error-operation
[a + '' for a in [1, 2]]
#! 3 type-error-operation
(a + '' for a in [1, 2])
#! 12 type-error-not-iterable
[a for a in 1]
tuple(str(a) for a in [1])
#! 8 type-error-operation
tuple(a + 3 for a in [''])
# ----------
# Some variables within are not defined
# ----------
#! 12 name-error
[1 for a in NOT_DEFINFED for b in a if 1]
#! 25 name-error
[1 for a in [1] for b in NOT_DEFINED if 1]
#! 12 name-error
[1 for a in NOT_DEFINFED for b in [1] if 1]
#! 19 name-error
(1 for a in [1] if NOT_DEFINED)
# ----------
# unbalanced sides.
# ----------
# ok
(1 for a, b in [(1, 2)])
#! 13 value-error-too-few-values
(1 for a, b, c in [(1, 2)])
#! 10 value-error-too-many-values
(1 for a, b in [(1, 2, 3)])

View file

@ -0,0 +1,13 @@
# classmethod
class TarFile():
@classmethod
def open(cls, name, **kwargs):
return cls.taropen(name, **kwargs)
@classmethod
def taropen(cls, name, **kwargs):
return name
# should just work
TarFile.open('hallo')

View file

@ -0,0 +1,7 @@
def generator():
yield 1
#! 11 type-error-not-subscriptable
generator()[0]
list(generator())[0]

View file

@ -0,0 +1,5 @@
"""
Another import tree, this time not for completion, but static analysis.
"""
from .a import *

View file

@ -0,0 +1 @@
from . import b

View file

@ -0,0 +1,25 @@
#! 7 import-error
import not_existing
import os
from os.path import abspath
#! 20 import-error
from os.path import not_existing
from datetime import date
date.today
#! 5 attribute-error
date.not_existing_attribute
#! 14 import-error
from datetime.date import today
#! 16 import-error
import datetime.date
#! 7 import-error
import not_existing_nested.date
import os.path

View file

@ -0,0 +1,21 @@
a, b = {'asdf': 3, 'b': 'str'}
a
x = [1]
x[0], b = {'a': 1, 'b': '2'}
dct = {3: ''}
for x in dct:
pass
#! 4 type-error-not-iterable
for x, y in dct:
pass
# Shouldn't cause issues, because if there are no types (or we don't know what
# the types are, we should just ignore it.
#! 0 value-error-too-few-values
a, b = []
#! 7 name-error
a, b = NOT_DEFINED

View file

@ -0,0 +1,7 @@
def raises():
raise KeyError()
def wrong_name():
#! 6 name-error
raise NotExistingException()

View file

@ -0,0 +1,16 @@
-1 + 1
1 + 1.0
#! 2 type-error-operation
1 + '1'
#! 2 type-error-operation
1 - '1'
-1 - - 1
-1 - int()
int() - float()
float() - 3.0
a = 3
b = ''
#! 2 type-error-operation
a + b

View file

@ -0,0 +1,11 @@
"""
Some special cases of Python 2.
"""
# python <= 2.7
# print is syntax:
print 1
print(1)
#! 6 name-error
print NOT_DEFINED

View file

@ -0,0 +1,119 @@
# -----------------
# *args
# -----------------
def simple(a):
return a
def nested(*args):
return simple(*args)
nested(1)
#! 6 type-error-too-few-arguments
nested()
def nested_no_call_to_function(*args):
return simple(1, *args)
def simple2(a, b, c):
return b
def nested(*args):
return simple2(1, *args)
def nested_twice(*args1):
return nested(*args1)
nested_twice(2, 3)
#! 13 type-error-too-few-arguments
nested_twice(2)
#! 19 type-error-too-many-arguments
nested_twice(2, 3, 4)
# A named argument can be located before *args.
def star_args_with_named(*args):
return simple2(c='', *args)
star_args_with_named(1, 2)
# -----------------
# **kwargs
# -----------------
def kwargs_test(**kwargs):
return simple2(1, **kwargs)
kwargs_test(c=3, b=2)
#! 12 type-error-too-few-arguments
kwargs_test(c=3)
#! 12 type-error-too-few-arguments
kwargs_test(b=2)
#! 22 type-error-keyword-argument
kwargs_test(b=2, c=3, d=4)
#! 12 type-error-multiple-values
kwargs_test(b=2, c=3, a=4)
def kwargs_nested(**kwargs):
return kwargs_test(b=2, **kwargs)
kwargs_nested(c=3)
#! 13 type-error-too-few-arguments
kwargs_nested()
#! 19 type-error-keyword-argument
kwargs_nested(c=2, d=4)
#! 14 type-error-multiple-values
kwargs_nested(c=2, a=4)
# TODO reenable
##! 14 type-error-multiple-values
#kwargs_nested(b=3, c=2)
# -----------------
# mixed *args/**kwargs
# -----------------
def simple_mixed(a, b, c):
return b
def mixed(*args, **kwargs):
return simple_mixed(1, *args, **kwargs)
mixed(1, 2)
mixed(1, c=2)
mixed(b=2, c=3)
mixed(c=4, b='')
# need separate functions, otherwise these might swallow the errors
def mixed2(*args, **kwargs):
return simple_mixed(1, *args, **kwargs)
#! 7 type-error-too-few-arguments
mixed2(c=2)
#! 7 type-error-too-few-arguments
mixed2(3)
#! 13 type-error-too-many-arguments
mixed2(3, 4, 5)
# TODO reenable
##! 13 type-error-too-many-arguments
#mixed2(3, 4, c=5)
#! 7 type-error-multiple-values
mixed2(3, b=5)
# -----------------
# plain wrong arguments
# -----------------
#! 12 type-error-star-star
simple(1, **[])
#! 12 type-error-star-star
simple(1, **1)
class A(): pass
#! 12 type-error-star-star
simple(1, **A())
#! 11 type-error-star
simple(1, *1)

View file

@ -0,0 +1,89 @@
try:
#! 4 attribute-error
str.not_existing
except TypeError:
pass
try:
str.not_existing
except AttributeError:
#! 4 attribute-error
str.not_existing
pass
try:
import not_existing_import
except ImportError:
pass
try:
#! 7 import-error
import not_existing_import
except AttributeError:
pass
# -----------------
# multi except
# -----------------
try:
str.not_existing
except (TypeError, AttributeError): pass
try:
str.not_existing
except ImportError:
pass
except (NotImplementedError, AttributeError): pass
try:
#! 4 attribute-error
str.not_existing
except (TypeError, NotImplementedError): pass
# -----------------
# detailed except
# -----------------
try:
str.not_existing
except ((AttributeError)): pass
try:
#! 4 attribute-error
str.not_existing
except [AttributeError]: pass
# Should be able to detect errors in except statement as well.
try:
pass
#! 7 name-error
except Undefined:
pass
# -----------------
# inheritance
# -----------------
try:
undefined
except Exception:
pass
# should catch everything
try:
undefined
except:
pass
# -----------------
# kind of similar: hasattr
# -----------------
if hasattr(str, 'undefined'):
str.undefined
str.upper
#! 4 attribute-error
str.undefined2
#! 4 attribute-error
int.undefined
else:
str.upper
#! 4 attribute-error
str.undefined