Python: Better test for Argument.getDefault(i)

Default values for positional arugments follow a rule, so if an argument has a
default value, later positional arguments must also have default values.

The database only stores the actual default values, and nothing about the
arguments that doesn't have default values.

This turns out to be a major problem for Argument.getKwDefault(i), since default
values for keyword-only arguments doesn't have the same rule. So if you know
there is one default value, you can't tell if it is associated with `foo` or
`bar`, as in the examples below:

```
def a(*, foo=None, bar):
    pass

def b(*, foo, bar=None):
    pass
```
This commit is contained in:
Rasmus Wriedt Larsen
2020-04-27 15:24:05 +02:00
parent 5f6058363f
commit 1fcbb6e9f4
12 changed files with 27 additions and 14 deletions

View File

@@ -1,4 +0,0 @@
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:5:21:5:22 | UnaryExpr |
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:7:19:7:20 | UnaryExpr |
| test.py:23:1:31:2 | FunctionExpr | Arguments | test.py:25:28:25:31 | None |
| test.py:23:1:31:2 | FunctionExpr | Arguments | test.py:26:20:26:23 | None |

View File

@@ -1,4 +0,0 @@
import python
from FunctionExpr fe
select fe, fe.getArgs(), fe.getArgs().getADefault()

View File

@@ -1,2 +0,0 @@
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:9:25:9:26 | UnaryExpr |
| test.py:23:1:31:2 | FunctionExpr | Arguments | test.py:29:32:29:35 | None |

View File

@@ -1,4 +0,0 @@
import python
from FunctionExpr fe
select fe, fe.getArgs(), fe.getArgs().getAKwDefault()

View File

@@ -0,0 +1,3 @@
| test.py:4:1:11:2 | FunctionExpr | 0 | test.py:5:15:5:17 | int |
| test.py:4:1:11:2 | FunctionExpr | 1 | test.py:7:13:7:15 | int |
| test.py:23:1:31:2 | FunctionExpr | 1 | test.py:25:20:25:24 | Str |

View File

@@ -0,0 +1,4 @@
import python
from FunctionExpr fe, int i
select fe, i, fe.getArgs().getAnnotation(i)

View File

@@ -0,0 +1,4 @@
| test.py:4:1:11:2 | FunctionExpr | 0 | test.py:5:21:5:22 | UnaryExpr |
| test.py:4:1:11:2 | FunctionExpr | 1 | test.py:7:19:7:20 | UnaryExpr |
| test.py:23:1:31:2 | FunctionExpr | 0 | test.py:25:28:25:31 | None |
| test.py:23:1:31:2 | FunctionExpr | 1 | test.py:26:20:26:23 | None |

View File

@@ -0,0 +1,4 @@
import python
from FunctionExpr fe, int i
select fe, i, fe.getArgs().getDefault(i)

View File

@@ -0,0 +1,2 @@
| test.py:4:1:11:2 | FunctionExpr | 0 | test.py:9:19:9:21 | int |
| test.py:23:1:31:2 | FunctionExpr | 1 | test.py:29:24:29:28 | Str |

View File

@@ -0,0 +1,4 @@
import python
from FunctionExpr fe, int i
select fe, i, fe.getArgs().getKwAnnotation(i)

View File

@@ -0,0 +1,2 @@
| test.py:4:1:11:2 | FunctionExpr | 0 | test.py:9:25:9:26 | UnaryExpr |
| test.py:23:1:31:2 | FunctionExpr | 0 | test.py:29:32:29:35 | None |

View File

@@ -0,0 +1,4 @@
import python
from FunctionExpr fe, int i
select fe, i, fe.getArgs().getKwDefault(i)