OILS / mycpp / examples / invalid_other.py View on Github | oilshell.org

63 lines, 26 significant
1#!/usr/bin/env python2
2"""
3Misc
4"""
5from __future__ import print_function
6
7import os
8
9from mycpp.mylib import log
10
11from typing import List
12
13
14def run_tests():
15 # type: () -> None
16
17 f = lambda i: i + 1
18
19 dict_comp = {k: 42 for k in [1, 2, 3]}
20
21 set_comp = {k for k in [1, 2, 3]}
22
23 # This is visited as part of list comprehension
24 #gen = (x for x in [1, 2, 3])
25
26 exec('x = 42')
27
28 # ok
29 assign_to_listcomp = ['t' for s in xrange(5)]
30
31 # Not ok
32 mylist = [] # type: List[List[str]]
33 mylist.append(['s' for s in xrange(3)])
34
35
36class A:
37 pass
38
39
40class B:
41 pass
42
43
44class Child(A, B):
45 pass
46
47
48# Doesn't need to be checked, because it fails at runtime
49#class Child2('invalid'):
50# pass
51
52
53def run_benchmarks():
54 # type: () -> None
55 raise NotImplementedError()
56
57
58if __name__ == '__main__':
59 if os.getenv('BENCHMARK'):
60 log('Benchmarking...')
61 run_benchmarks()
62 else:
63 run_tests()