[issue43923] Can't create generic NamedTuple as of py3.9

2022-03-07 Thread Steven Silvester


Steven Silvester  added the comment:

The use case that prompted https://github.com/python/cpython/pull/31679 is that 
we are adding typings to `PyMongo`.  We are late to using typings,  because we 
only recently dropped Python 2.7 support.  

We have an existing options class that subclasses `NamedTuple`.  We would like 
to make that class `Generic`, but are currently blocked.  

Our current workaround is to create a separate stub file that uses `class 
CodecOptions(Tuple, Generic[T])` and explicitly re-declares the `NamedTuple` 
API.

Switching to `dataclass` would be disruptive, since we still support Python 3.6 
and only rely on the standard library.  We would also require a major version 
update since it would be an API change.

--
nosy: +Steven Silvester

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



[issue43923] Can't create generic NamedTuple as of py3.9

2022-03-08 Thread Steven Silvester


Steven Silvester  added the comment:

I agree we're stuck with the typing stub workaround for our use case.  We can 
re-submit a "fix forward" PR.

--

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



[issue34380] Relax Restrictions on await?

2018-08-11 Thread Steven Silvester


New submission from Steven Silvester :

When writing an `async` function, we often want to `await` a method call that 
may or may not be `async`.  For instance, it may be synchronous in the base 
class, but asynchronous in the subclass on the instance we have been given.  It 
would be nice for `await foo` to be a no-op if `foo` does not have an 
`__await__` method.  For instance, the following works in EMCAScript 2017:  
`async function foo () { let bar = await 1; console.log(bar); }`.  As a 
workaround, we have been using `await force_async(foo.bar)`, where 
`force_async` is the following:

```python
async def force_async(obj):
"""Force an object to be asynchronous"""
if hasattr(obj, '__await__'):
return await obj
async def inner():
return obj
return await inner()
```

This functionality is roughly equivalent to `gen.maybe_future` for coroutines, 
that is now deprecated in Tornado.  cf 
http://www.tornadoweb.org/en/stable/gen.html#tornado.gen.maybe_future

--
components: asyncio
messages: 323410
nosy: Steven Silvester, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Relax Restrictions on await?
versions: Python 3.8

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



[issue34380] Relax Restrictions on await?

2018-08-11 Thread Steven Silvester


Steven Silvester  added the comment:

Thanks for your consideration and for implementing the original feature!

--

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