Message327840
This issue is found from a type hinting problem:
```
class ImportFrom(stmt): class ImportFrom(stmt):
module = ... # type: Optional[_identifier] module = ... # type: Optional[_identifier]
names = ... # type: typing.List[alias] names = ... # type: typing.List[alias]
level = ... # type: Optional[int]
```
As we can see that `level` here is optional, and it's strange.
I tried `ast.parse` on both Python 3.5/3.6, and found that None of `from a import *`, `from .a import *`, `from ..a import *` and other regular cases result into an ImportFrom AST whose `level` is None.
Then I went to Python-asdl: https://github.com/python/cpython/blob/137b0632dccb992ca11e9445142fb33a29c33a51/Parser/Python.asdl#L44
and got
ImportFrom(identifier? module, alias* names, int? level)
It seems like a bug. To validate it, I went to https://github.com/python/cpython/blob/97cf0828727ac2a269c89c5aa09570a69a22c83c/Python/ast.c#L3311
and got
static stmt_ty
ast_for_import_stmt(struct compiling *c, const node *n){
int idx, ndots = 0;
...
return ImportFrom(modname, aliases, ndots, lineno, col_offset, c->c_arena);
...
}
It seems that no reason for `level` being None.
If it's really a bug, IMO it could be also an example that type hinting helps to error detection :-) |
|
Date |
User |
Action |
Args |
2018-10-16 18:39:56 | thautwarm | set | recipients:
+ thautwarm, docs@python |
2018-10-16 18:39:56 | thautwarm | set | messageid: <1539715196.88.0.788709270274.issue35001@psf.upfronthosting.co.za> |
2018-10-16 18:39:56 | thautwarm | link | issue35001 messages |
2018-10-16 18:39:56 | thautwarm | create | |
|