[issue35001] ImportFrom level cannot be optional

2018-10-18 Thread Brett Cannon
Brett Cannon added the comment: There aren't any type hints in the 'ast' module in Python itself, so this is an issue with typeshed. Closing as "third party". -- nosy: +brett.cannon resolution: -> third party stage: -> resolved status: open -> closed

[issue35001] ImportFrom level cannot be optional

2018-10-17 Thread thautwarm
thautwarm added the comment: Firstly, allowing to construct ImportFrom without `level` specified could be the result of referring Python-asdl. Secondly, in C level, `level` is always an integer. Last but not the least, when you can access `level` from an ImportFrom AST, it must be an

[issue35001] ImportFrom level cannot be optional

2018-10-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The level argument of ast.ImportFrom is optional. If it is not specified or None is passes, the corresponding attribute is set to the default value 0. Type hints are not used in the stdlib. If this is a bug in mypy, this is not the proper tracker for

[issue35001] ImportFrom level cannot be optional

2018-10-17 Thread thautwarm
thautwarm added the comment: @Anthony > I don't think mypy has an annotation for "sometimes has an attribute" Yes.. The annotation for an attribute that **maybe exist** cannot be expressed by mypy.. -- ___ Python tracker

[issue35001] ImportFrom level cannot be optional

2018-10-17 Thread thautwarm
thautwarm added the comment: Hi, Serhiy, for Python-asdl has made `level` able to optional, certainly we could construct an ImportFrom AST without giving `level`. Moreover, this might evidence that `level` cannot be optional in fact:

[issue35001] ImportFrom level cannot be optional

2018-10-16 Thread Anthony Sottile
Anthony Sottile added the comment: Hmmm, I don't think mypy has an annotation for "sometimes has an attribute" -- `Optional[T]` is `Union[T, None]` (why I tried `None`). But you're right, `FromImport` is constructable without a `level` -- it seems to behave as `level=0` (I guess as

[issue35001] ImportFrom level cannot be optional

2018-10-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: None is not integer. This field is optional: >>> from ast import * >>> x = Module(body=[ImportFrom(names=[alias(name='path', asname=None)], >>> lineno=1, col_offset=0)]) >>> compile(x, '', 'exec') at 0x7f73b754da00, file "", line 1> -- nosy:

[issue35001] ImportFrom level cannot be optional

2018-10-16 Thread Anthony Sottile
Anthony Sottile added the comment: In fact, trying to use an `ImportFrom` without an integer `level` results in a `ValueError`: >>> x = ast.parse('from os import path') >>> x.body[0].level = None >>> compile(x, '', 'exec') Traceback (most recent call last): File "", line 1, in ValueError:

[issue35001] ImportFrom level cannot be optional

2018-10-16 Thread Anthony Sottile
Anthony Sottile added the comment: It appears it has always had this bug since introduction of absolute/relative imports in https://github.com/python/cpython/commit/f7f438ba3b05eb4356e7511401686b07d9dfb6d8 Agree with changing this to `# type: int` and correcting the documentation

[issue35001] ImportFrom level cannot be optional

2018-10-16 Thread Sebastian Rittau
Change by Sebastian Rittau : -- nosy: +srittau ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue35001] ImportFrom level cannot be optional

2018-10-16 Thread thautwarm
New submission from thautwarm : 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 = ...