File: test21.py

package info (click to toggle)
pychecker 0.8.19-10
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,484 kB
  • ctags: 2,114
  • sloc: python: 9,968; sh: 98; makefile: 13
file content (57 lines) | stat: -rw-r--r-- 1,017 bytes parent folder | download | duplicates (9)
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
'test inconsistent return types'

a, b = 0, 0

def f(z):
    'should be a warning'
    if z:
        return 1
    return  []

def g(z):
    'should be a warning'
    if z:
        return (1, 2)
    return  []

def h(z):
    'should be a warning'
    if z:
        return {}
    return  []

def y():
    'should not be a warning'
    if a: return 1
    elif b: return 0
    else : return cmp(a, b)

def z():
    'should not be a warning'
    if b: return b, a, globals()
    return 1, 2, 3

class A:
    'test returning base class'

class B(A):
    'test returning derived class'

def x(num):
    if num == 1:
        return A()
    if num == 2:
        return B()
    return None

class C:
    'test returning "inconsistent" types from __getattr__ which is allowed'
    def __getattr__(self, attr):
        if attr == 'a':
            return 1
        if attr == 'b':
            return 3.1415926
        if attr == 'b':
            return 'string'
        raise AttributeError, 'no attr ' + attr + ' is a bad attr'