[issue29922] error message when __aexit__ is not async

2018-04-04 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

Since BEFORE_ASYNC_WITH always is followed by GET_AWAITABLE, in future they can 
be merged into a single instruction (like GET_ANEXT or GET_YIELD_FROM_ITER).

--
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



[issue29922] error message when __aexit__ is not async

2018-04-04 Thread miss-islington

miss-islington  added the comment:


New changeset 1487cd14bb1e04de5b98fffc5ec41c6cf6b5d5f1 by Miss Islington (bot) 
in branch '3.6':
bpo-29922: Add more tests for error messages in 'async with'. (GH-6370)
https://github.com/python/cpython/commit/1487cd14bb1e04de5b98fffc5ec41c6cf6b5d5f1


--

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-04 Thread miss-islington

Change by miss-islington :


--
pull_requests: +6084

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-04 Thread miss-islington

miss-islington  added the comment:


New changeset 785f36c876721c12f653371e9893527a25140624 by Miss Islington (bot) 
in branch '3.7':
bpo-29922: Add more tests for error messages in 'async with'. (GH-6370)
https://github.com/python/cpython/commit/785f36c876721c12f653371e9893527a25140624


--

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-04 Thread miss-islington

Change by miss-islington :


--
pull_requests: +6082

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-04 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset 2eeac269dd1e04a2a179384576986c3e47895ee0 by Serhiy Storchaka in 
branch 'master':
bpo-29922: Add more tests for error messages in 'async with'. (GH-6370)
https://github.com/python/cpython/commit/2eeac269dd1e04a2a179384576986c3e47895ee0


--

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-04 Thread miss-islington

miss-islington  added the comment:


New changeset 4fd6c27dc8ba7ca97aa70e1ab98729f2207bbe19 by Miss Islington (bot) 
in branch '3.6':
bpo-29922: Improve error messages in 'async with' (GH-6352)
https://github.com/python/cpython/commit/4fd6c27dc8ba7ca97aa70e1ab98729f2207bbe19


--

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-04 Thread miss-islington

miss-islington  added the comment:


New changeset fcd4e03e08a2d4ec1cde17beb66e2b22a052500f by Miss Islington (bot) 
in branch '3.7':
bpo-29922: Improve error messages in 'async with' (GH-6352)
https://github.com/python/cpython/commit/fcd4e03e08a2d4ec1cde17beb66e2b22a052500f


--
nosy: +miss-islington

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-04 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
pull_requests: +6081

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-02 Thread Yury Selivanov

Yury Selivanov  added the comment:

3.5 is in security fixes only, so don't bother.

--

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-02 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

It would be hard to backport this to 3.5. Wordcode allows scanning back.

--

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-02 Thread miss-islington

Change by miss-islington :


--
pull_requests: +6063

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-02 Thread miss-islington

Change by miss-islington :


--
pull_requests: +6062

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-02 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset a68f2f0578bbf812fa2264d0e0bb388340d6e230 by Serhiy Storchaka in 
branch 'master':
bpo-29922: Improve error messages in 'async with' (GH-6352)
https://github.com/python/cpython/commit/a68f2f0578bbf812fa2264d0e0bb388340d6e230


--

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-02 Thread Ned Deily

Ned Deily  added the comment:

> Can we backport it to 3.6 too?

I suppose so.  (Though you'll owe me if you break anything.)

--
versions: +Python 3.6

___
Python tracker 

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




[issue29922] error message when __aexit__ is not async

2018-04-02 Thread Yury Selivanov

Yury Selivanov  added the comment:

> PR 6352 smells like a bug fix to me and I think it should be OK for 3.7.0b4.

Can we backport it to 3.6 too?

--

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-02 Thread Ned Deily

Ned Deily  added the comment:

PR 6352 smells like a bug fix to me and I think it should be OK for 3.7.0b4.

--
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



[issue29922] error message when __aexit__ is not async

2018-04-02 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

This issue looks unrelated to issue25538.

PR 6352 improves error messages without changing bytecode. It is so simple that 
could be backported to 3.7 if Ned approves this.

But it conflicts with issue32949. This way will not work after merging any of 
current issue32949 PRs. We will have to find other way for issue32949.

--
nosy: +Mark.Shannon, ned.deily, serhiy.storchaka
superseder: Traceback from __exit__ method is misleading -> 

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2018-04-02 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
keywords: +patch
pull_requests: +6061
stage: needs patch -> patch review

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2017-12-20 Thread Yury Selivanov

Change by Yury Selivanov :


--
versions: +Python 3.8 -Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 
3.6, Python 3.7

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2017-12-20 Thread Andrew Svetlov

Andrew Svetlov  added the comment:

It's Interpreter Core problem, not specific to asyncio bug.

--
components: +Interpreter Core -asyncio
nosy: +asvetlov

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2017-03-31 Thread Ivan Levkivskyi

Changes by Ivan Levkivskyi :


--
nosy: +levkivskyi

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2017-03-29 Thread Frazer McLean

Changes by Frazer McLean :


--
nosy: +RazerM

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2017-03-28 Thread Chewy

Changes by Chewy :


--
nosy: +Chewy

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2017-03-27 Thread Yury Selivanov

Yury Selivanov added the comment:

> Would it maybe make sense to implement this as adding an argument to 
> GET_AWAITABLE to indicate whether it was called from await, __anext__, 
> __aenter__ or __aexit__?

Yes, but it will make it a tad slower (which will also affect await 
performance).  I'll run some benchmarks.

--

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2017-03-27 Thread Yury Selivanov

Changes by Yury Selivanov :


--
resolution: duplicate -> 
stage: resolved -> needs patch
status: closed -> open

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2017-03-27 Thread Tadhg McDonald-Jensen

Tadhg McDonald-Jensen added the comment:

> This is a specific example of the general problem reported in issue 25538.

Definitely related, although the part of giving an error "... can't be used in 
'await' expression" when no await expression is used isn't covered by that 
thread so I'm not sure I'd call this a direct duplicate.


Currently when __anext__ return a non-awaitable this error is shown:

TypeError: 'async for' received an invalid object from __anext__: NoneType

So having __aenter__ and __aexit__ have similar error messages would be nice.

Would it maybe make sense to implement this as adding an argument to 
GET_AWAITABLE to indicate whether it was called from await, __anext__, 
__aenter__ or __aexit__? (or others that may exist in future)  I don't know 
enough about bytecode to know how it'd compare to an instruction for each case.

--

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2017-03-27 Thread Yury Selivanov

Yury Selivanov added the comment:

> This is a specific example of the general problem reported in issue 25538.

It's a bit different code path/problem.  But I agree, we should work on making 
both `with` and `async with` a bit more usable.

> Would it be possible to change this so it indicates that it was the context 
> that was invalid not an `await` statement?

I'm not sure if we can do anything about this.  We compile 'async with' into a 
set of opcodes.  The first ones resolve __aexit__, the latter ones await on it. 
The one that prepares to await on the aexit (GET_AWAITABLE) is the same that 
'await' expression compiles to, and that opcode has no idea what exactly it 
awaits on.

We could probably add GET_AEXIT_AWAITABLE opcode specifically to improve the 
error message (other than that it would be a copy of GET_AWAITABLE). I'll think 
about it.

--
assignee:  -> yselivanov

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2017-03-27 Thread R. David Murray

R. David Murray added the comment:

This is a specific example of the general problem reported in issue 25538.

--
nosy: +r.david.murray
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> Traceback from __exit__ method is misleading

___
Python tracker 

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



[issue29922] error message when __aexit__ is not async

2017-03-27 Thread Tadhg McDonald-Jensen

New submission from Tadhg McDonald-Jensen:

When creating a asynchronous context manager if the __aexit__ method is not 
labeled as async (so it returns None instead of a coroutine) the error has a 
generic error message:

TypeError: object NoneType can't be used in 'await' expression

Would it be possible to change this so it indicates that it was the context 
that was invalid not an `await` statement?  Since the traceback points to the 
last statement of the with block it can create very confusing errors if the 
last statement was an await.

Example:

import asyncio
class Test():
async def __aenter__(self):
print("aenter used")
value = asyncio.Future()
value.set_result(True)
return value
#FORGOT TO MARK AS async !!
def __aexit__(self, *errors):
print("aexit used")
return None

async def my_test():
async with Test() as x:
print("inside async with, now awaiting on", x)
await x

my_test().send(None)

Give the output:

aenter used
inside async with, now awaiting on 
aexit used
Traceback (most recent call last):
  File ".../test.py", line 19, in 
my_test().send(None)
  File ".../test.py", line 16, in my_test
await x
TypeError: object NoneType can't be used in 'await' expression

Which indicates to me that `x` was None when it was await-ed for.

--
components: asyncio
messages: 290630
nosy: Tadhg McDonald-Jensen, yselivanov
priority: normal
severity: normal
status: open
title: error message when __aexit__ is not async
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

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