[issue34921] NoReturn not allowed by get_type_hints when future import annotations is used

2018-11-28 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:


New changeset f71a5922916abd6cc7bf7d99ed4715b6e96e5981 by Ivan Levkivskyi (Ismo 
Toijala) in branch '3.7':
bpo-34921: Allow escaped NoReturn in get_type_hints (GH-9750) (GH-10772)
https://github.com/python/cpython/commit/f71a5922916abd6cc7bf7d99ed4715b6e96e5981


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34921] NoReturn not allowed by get_type_hints when future import annotations is used

2018-11-28 Thread Ismo Toijala


Change by Ismo Toijala :


--
pull_requests: +10016

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34921] NoReturn not allowed by get_type_hints when future import annotations is used

2018-10-08 Thread Ivan Levkivskyi


Change by Ivan Levkivskyi :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34921] NoReturn not allowed by get_type_hints when future import annotations is used

2018-10-08 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:


New changeset 5eea0ad50c32d38909ff4e29309e2cc3c6ccb2c0 by Ivan Levkivskyi (Noah 
Wood) in branch 'master':
bpo-34921: Allow escaped NoReturn in get_type_hints (GH-9750)
https://github.com/python/cpython/commit/5eea0ad50c32d38909ff4e29309e2cc3c6ccb2c0


--
nosy: +levkivskyi

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34921] NoReturn not allowed by get_type_hints when future import annotations is used

2018-10-07 Thread noah


noah  added the comment:

Is this a feature request? Because it doesn't look like a bug to me. Where 
NoReturn is defined it says it's supposed to fail in static type checkers.

Anyway, I'm not entirely sure on the whole process of contributing but here 
goes:

The code ultimately fails at _type_check.
According to _type_check, "special forms like Union are not valid, while 
Union[int, str] is OK, etc."

NoReturn isn't subscriptable.

So basically the code is getting to this point and executing

_type_check(NoReturn, msg)

which fails on any special form.

If you try to force NoReturn to have additional parameters it will fail at 
__getitem__ because NoReturn is not subscriptable.

Any is also not subscriptable, but it's specifically handled in the 
_type_check() function ala:

if (isinstance(arg, _SpecialForm) and arg is not Any or ...

if you wanted to add NoReturn you could do something like

if (isinstance(arg, _SpecialForm) and arg not in [Any, NoReturn] or ...

Tested it and it works fine on 3.7 and 3.8 for me!

I've submitted a pull request with my proposed fix

--
nosy: +ngwood111 -levkivskyi, xtreak
versions: +Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34921] NoReturn not allowed by get_type_hints when future import annotations is used

2018-10-07 Thread noah


Change by noah :


--
keywords: +patch
pull_requests: +9136
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34921] NoReturn not allowed by get_type_hints when future import annotations is used

2018-10-07 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Thanks for the report. I am adding Ivan who might have a better explanation 
since this is related to typing and type(NoReturn) has  with __future__ import and  without 
__future__. Ivan, feel free to remove yourself if this irrelevant.

--
nosy: +levkivskyi, xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34921] NoReturn not allowed by get_type_hints when future import annotations is used

2018-10-07 Thread Ismo Toijala


New submission from Ismo Toijala :

The following example should work but does not.
Note that it does work without the future import.

from __future__ import annotations

import typing

def f() -> typing.NoReturn:
pass

typing.get_type_hints(f)

Traceback (most recent call last):
  File "foo.py", line 8, in 
typing.get_type_hints(f)
  File "/usr/lib/python3.7/typing.py", line 1001, in get_type_hints
value = _eval_type(value, globalns, localns)
  File "/usr/lib/python3.7/typing.py", line 260, in _eval_type
return t._evaluate(globalns, localns)
  File "/usr/lib/python3.7/typing.py", line 466, in _evaluate
is_argument=self.__forward_is_argument__)
  File "/usr/lib/python3.7/typing.py", line 135, in _type_check
raise TypeError(f"Plain {arg} is not valid as type argument")
TypeError: Plain typing.NoReturn is not valid as type argument

--
components: Library (Lib)
messages: 327274
nosy: itoijala
priority: normal
severity: normal
status: open
title: NoReturn not allowed by get_type_hints when future import annotations is 
used
type: behavior
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com