@@ 1574-1590 (lines=17) @@ | ||
1571 | self.runs(key_arg) |
|
1572 | self.runs(cmp_to_key, from_version((2, 7))) |
|
1573 | ||
1574 | def test_c_func_takes_no_keyword_arguments(self): |
|
1575 | """TODO.""" |
|
1576 | # http://stackoverflow.com/questions/24463202/typeerror-get-takes-no-keyword-arguments |
|
1577 | # https://www.python.org/dev/peps/pep-0457/ |
|
1578 | # https://www.python.org/dev/peps/pep-0436/#functions-with-positional-only-parameters |
|
1579 | sugg = NO_KEYWORD_ARG_MSG |
|
1580 | code = 'dict().get(0, {0}None)' |
|
1581 | good_code, bad_code = format_str(code, '', 'default=') |
|
1582 | self.runs(good_code) |
|
1583 | self.throws(bad_code, NOKWARGS, sugg, interpreters='cpython') |
|
1584 | self.runs(bad_code, interpreters='pypy') |
|
1585 | # It would be better to have the suggestion only when the function |
|
1586 | # doesn't accept keyword arguments but does accept positional |
|
1587 | # arguments but we cannot use introspection on builtin function. |
|
1588 | code2 = 'globals({0})' |
|
1589 | good_code, bad_code1, bad_code2 = format_str(code2, '', '2', 'foo=2') |
|
1590 | self.runs(good_code) |
|
1591 | self.throws(bad_code1, NBARGERROR) |
|
1592 | self.throws(bad_code2, NBARGERROR, interpreters='pypy') |
|
1593 | self.throws(bad_code2, NOKWARGS, sugg, interpreters='cpython') |
|
@@ 1504-1518 (lines=15) @@ | ||
1501 | typo, good = 'abcdf', 'abcdef' |
|
1502 | sugg = quote(good) |
|
1503 | code = 'f = lambda arg1, ' + good + ': None\nf(42, {0}=None)' |
|
1504 | bad_code, good_code = format_str(code, typo, good) |
|
1505 | self.throws(bad_code, UNEXPECTEDKWARG, sugg) |
|
1506 | self.runs(good_code) |
|
1507 | ||
1508 | def test_keyword_arg_lambda_method(self): |
|
1509 | """Test with lambda methods instead of usual methods.""" |
|
1510 | typo, good = 'abcdf', 'abcdef' |
|
1511 | sugg = quote(good) |
|
1512 | code = 'class MyClass:\n\tfunc = lambda self, ' + good + ': None' \ |
|
1513 | '\nMyClass().func({0}=1)' |
|
1514 | bad_code, good_code = format_str(code, typo, good) |
|
1515 | self.throws(bad_code, UNEXPECTEDKWARG, sugg) |
|
1516 | self.runs(good_code) |
|
1517 | ||
1518 | def test_keyword_arg_other_objects_with_name(self): |
|
1519 | """Mix of previous tests but with more objects defined. |
|
1520 | ||
1521 | Non-function object with same same as the function tested are defined |
|
@@ 2240-2252 (lines=13) @@ | ||
2237 | self.throws(bad_code, NOBINDING, sugg, after) |
|
2238 | ||
2239 | def test_nonlocal4(self): |
|
2240 | """suggest close matches to variable name.""" |
|
2241 | # NICE_TO_HAVE (needs access to variable in enclosing scope) |
|
2242 | before, after = before_and_after((3, 0)) |
|
2243 | code = 'def func():\n\tfoo = 1\n\tdef nested():\n\t\tnonlocal {0}' |
|
2244 | typo, good = 'foob', 'foo' |
|
2245 | bad_code, good_code = format_str(code, typo, good) |
|
2246 | self.throws(good_code, INVALIDSYNTAX, [], before) |
|
2247 | self.runs(good_code, after) |
|
2248 | self.throws(bad_code, INVALIDSYNTAX, [], before) |
|
2249 | self.throws(bad_code, NOBINDING, [], after) |
|
2250 | ||
2251 | def test_nonlocal_at_module_level(self): |
|
2252 | """nonlocal must be used in function.""" |
|
2253 | before, mid, after = before_mid_and_after((2, 7), (3, 0)) |
|
2254 | code = 'nonlocal foo' |
|
2255 | self.throws(code, UNEXPECTED_OEF, [], before) |