mypy does not detect this as a problem because EnumMeta has a `.__len__` method
https://github.com/python/typeshed/blob/60939b00afede13feeec3cee6f6dfe6eb2df1593/stdlib/enum.pyi#L121
what would the type hints look like if len(Enum) failed but class Foo(Enum):
pass len(Foo) succeeds?
I'd recommend writing a virtualenv plugin that configures
https://virtualenv.pypa.io/en/latest/extend.html#virtualenv.discovery.discover.Discover
Overriding the interpreter install path here:
> A practical approach may be to develop some form of library that "hides"
the difference behind some form of API for finding the correct value, get
that added to the stdlib and wait a few years until it's adopted everywhere
(because it's so well-designed and convenient ;-)) Then, you can change
The generic collections in typing were deprecated in favor of the generic
collections in collections.abc. The objects and the types were exposed to
user code, and in the future they will not be
> We don't want there to be warnings about them
> forever
The new wanrings._deprecated
No because existence of this attribute is dynamic
On Fri, Jun 25, 2021, 3:44 PM Guido van Rossum wrote:
> Would a static type checker have found this?
>
> On Fri, Jun 25, 2021 at 02:07 Thomas Grainger wrote:
>
>> I was debugging some code that was using TLSv1.2 when I expe
urllib3 was also burned by this problem
https://github.com/urllib3/urllib3/issues/2636
On Fri, Jul 9, 2021, 5:39 PM Thomas Grainger wrote:
> > if we find time to implement it for 3.11.
>
> https://www.python.org/dev/peps/pep-0543/#configuration
> was Withdrawn
>
> woul
Ricky Teachey wrote:
> Could this be a use case for typing.Annotated?
> In [6]: from dataclasses import dataclass
> In [7]: from typing import Annotated
> In [8]: class A:
>...: """Docstring for class A."""
>...: x: Annotated[int, "Docstring for x"]
>...: y: Annotated[bool,
Tom Pohl wrote:
> A question for the Python experts: What is the correct technical term for a
> functionality like "http.server", i.e., a module with an actual "main"
> function?
There's some details about it here
https://docs.python.org/3/library/__main__.html#idiomatic-usage
FYI you can already use package/__main__.py which is runnable with `python
-m package` and you don't need the `if __name__ == "__main__":`
https://docs.python.org/3.10/library/__main__.html#main-py-in-python-packages
On Fri, 1 Oct 2021, 20:39 Paul Bryan, wrote:
> How about the following?
>
>
`yield from (,)` produced different byte code when I tried it, so I think it's
a tad slower
Also yield from doesn't work in async generators
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to
I'd imagine that context manager here simply wouldn't cancel the current
task if the lock can be acquired in time:
```
async with lock.acquire(timeout=1.0):
await do_things_with_lock()
```
On Mon, 20 Sep 2021, 14:15 Gustavo Carneiro, wrote:
> On Mon, 20 Sept 2021 at 13:15, Chris
anyio provides a nice context manager that works in both asyncio and trio:
```
import anyio
async def async_fn():
with anyio.move_on_after(1.0) as scope:
async with lock:
scope.deadline = math.inf
await do_things_with_lock()
```
I really like json.loadf I'd also like to see a csv.loadf. not sure the `f`
is needed: you could use @functools.singledispatch
On Mon, 6 Sep 2021, 01:12 Christopher Barker, wrote:
> On Sun, Sep 5, 2021 at 10:32 AM David Mertz, Ph.D.
> wrote:
>
>> Most Pandas read methods take either a
Seems nice, tarfile has a similar shortcut too. I do tend to reach for
pandas now whenever I can for csv processing
On Sun, 5 Sep 2021, 16:10 C. Titus Brown via Python-ideas, <
python-ideas@python.org> wrote:
> Hi all,
>
> the product of Sunday morning idle curiosity...
>
> I’ve been using the
Serhiy Storchaka wrote:
> There are two different kinds of TypeError: if the end user passes an
> instance of wrong type and if the author of the library makes an error
> in implementation of some protocols.
> For example, len(obj) raises TypeError in two cases: if obj does not
> have __len__
the way to make an (aysnc)generator that immediately raises
Stop(Async)Iteration immediately is to insert an unreachable `yield` statement,
however there's two ways to do it:
def example():
if False:
yield
or:
def example():
return
yield
currently
Nick Parlante wrote:
> Hi there python-ideas - I've been teaching Python as a first
> programming language for a few years, and from that experience I want
> to propose a change to PEP8. I'm sure the default position for PEP8 is
> to avoid changing it. However, for this one rule I think a good
subprocess.run(args, capture_output=True, check=True, text=True,
encoding="utf8").stdout ?
On Thu, 26 Aug 2021, 13:55 Evan Greenup via Python-ideas, <
python-ideas@python.org> wrote:
> Currently, when what to execute external command, either os.system() or
> subprocess functions should be
Right but this doesn't work with bumpy or pandas
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
> This is a shortcoming of the language.
this could be fixed if the built-in bool checked to see if the value was a
numpy.array or a pandas.DataFrame and automatically called `array.size > 0` or
`df.empty`
___
Python-ideas mailing list --
here's another fun one "A False midnight": https://lwn.net/Articles/590299/
https://bugs.python.org/issue13936#msg212771
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
In all seriousness this is an actual problem with numpy/pandas arrays where:
```
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.array([1, 2, 3])
array([1, 2, 3])
>>>
bool((len(collection) == 0) is True) == True and issubclass(True, bool)
On Sun, 22 Aug 2021, 17:09 Valentin Berlier, wrote:
> > (len(collection) == 0) is True
>
> bool((len(collection) == 0) is True) == True
> ___
> Python-ideas mailing list --
asyncio.to_thread creates threads that inherit the current context, according
to https://www.python.org/dev/peps/pep-0567/#rationale the decimal module
should use contextvars for this too
___
Python-ideas mailing list -- python-ideas@python.org
To
Would a work stealing approach work better for you here? Then the only
signalling overhead would be when a core runs out of work
On Thu, 19 Aug 2021, 05:36 Stephen J. Turnbull, <
turnbull.stephen...@u.tsukuba.ac.jp> wrote:
> Christopher Barker writes:
>
> > The worker pool approach is probably
Jack DeVries wrote:
> Hi All!
> We are trying to replace a link in the official docs which is now
> broken, but used to link to this article:
> https://web.archive.org/web/20210613191914/https://developer.mozilla.org/en-...
> Can you offer a suggestion for a replacement? The bad link has already
>
It looks like the source moved here
https://github.com/mdn/archived-content/blob/main/files/en-us/mozilla/qa/bug_writing_guidelines/index.html
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to
It looks like it was removed unintentionally because the Mozilla support
pages still reference it
https://support.mozilla.org/en-US/kb/contributors-guide-writing-good-bug#w_existing-guidelines-for-writing-your-first-bug
On Mon, 16 Aug 2021, 18:30 Jack DeVries, wrote:
> > Is there a reason why
You can use `T | None`
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
Any has the same number of characters as All
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
how does it compare with the old:
```
def rh(ham, _bool=bool):
return _bool(ham)
```
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
Specially I'd like to be able to deprecate the `Callable[..., Iterable[T]]`
type of contextlib.contextmanager
See https://github.com/python/typeshed/pull/2773#issuecomment-458872741
On Thu, 29 Jul 2021, 22:00 Thomas Grainger, wrote:
> I'd like to be able to specificy @deprecate on only s
I'd like to be able to specificy @deprecate on only some @overloads
On Thu, 29 Jul 2021, 21:59 Paul Bryan, wrote:
> I'm +1 on deprecation decorator, with some way to represent it so that it
> can be determined at runtime (e.g. dunder).
>
>
> On Thu, 2021-07-29 at 20:52 +, Leonardo Freua
But heterogeneous iteration would require typing changes
On Thu, 29 Jul 2021, 02:18 Eric V. Smith, wrote:
> In dataclasses, support for __slots__ is being added in 3.10. Adding
> optional support for iteration would be easy.
>
> --
> Eric V. Smith
>
> On Jul 28, 2021, at 7:29 PM, Paul Bryan
I've thing I still use NamedTuple for is when I want type safe
heterogeneous iterable unpacking, which is only possible for tuples (and
NamedTuple) eg I'd like to be able to express both:
tx, rx = trio.MemoryChanel[int]()
And:
with trio.MemoryChannel[int]() as channel:
n.start_soon(worker,
Would fixing this help? https://bugs.python.org/issue44140
On Tue, 20 Jul 2021, 02:16 Sebastian Berg,
wrote:
> On Mon, 2021-07-19 at 22:24 +, Mark Gordon wrote:
> > Proposal:
> >
> > Have a weakref.link (not at all attached to the naming) primitive
> > that allows one to keep object A alive
Right but it's not a status code - it's a callback that you *must* call
On Fri, 16 Jul 2021, 17:17 MRAB, wrote:
> On 2021-07-16 12:44, Stephen J. Turnbull wrote:
> > Thomas Grainger writes:
> >
> > > Another example, is a cash point (ATM) won't give you your money
>
Another example, is a cash point (ATM) won't give you your money until you
take your card
On Fri, 16 Jul 2021, 09:28 Stephen J. Turnbull, <
turnbull.stephen...@u.tsukuba.ac.jp> wrote:
> Ethan Furman writes:
>
> > Isn't that javascript? Javascript idioms are not (necessarily)
> > Python
Like the nodeback interface, it's (err, val)
On Tue, 13 Jul 2021, 21:31 Ethan Furman, wrote:
> On 7/13/21 12:43 PM, Thomas Grainger wrote:
>
> > I used the order I did because it's idiomatic to return the value the
> user needs
> > followed by the value the use
also https://www.python.org/dev/peps/pep-0343/ probably needs updating - but
I'm not sure exactly what the code is
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
I used the order I did because it's idiomatic to return the value the user
needs followed by the value the user wants.
On Tue, 13 Jul 2021, 20:24 Serhiy Storchaka, wrote:
> 13.07.21 18:59, Thomas Grainger пише:
> > given that it's hard to implement this correctly I think the
currently lots of code manages contexts incorrectly by doing:
```
@dataclasses.dataclass
class WrapCmgr:
_cmgr: ContextManager[T]
def __enter__(self) -> Wrapped[T]:
return wrap(_cmgr.__enter__())
def __exit__(self, \, t: Type[BaseException] | None, v: BaseException, tb:
> It opens the file in the main thread, and not asynchronously, but doesn't
the file itself get read in the other thead, asynchronously? And is there
any extra RAM used?
The file could be on an external network drive and so opening it may block the
main thread for seconds:
```
with
It's a utility method, so its usefulness derives from being available
everywhere without having to patch it in.
For me what's changed is the introduction of `asyncio.to_thread` and PEP 597
making `pathlib.Path.open` slightly less ergonomic,
___
It's been brought up a few times eg:
https://github.com/python/cpython/pull/12465
but I really think it's time to be re-considered.
Specifically I love being able to use
`asyncio.to_thread(pathlib.Path(...).read_text, encoding="utf8")` It does
exactly the right thing for me! It's great
> if we find time to implement it for 3.11.
https://www.python.org/dev/peps/pep-0543/#configuration
was Withdrawn
would this need a new PEP?
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to
, 19:45 Brendan Barnwell, wrote:
> On 2021-06-28 07:03, Thomas Grainger wrote:
> >> >but in this case the object is security sensitive, and security should
> be much more rigorous in ensuring correctness.
> > It looks like there's a consensus being reached, should I create a b
I!
This is fixed in the default branch however
https://github.com/encode/httpx/pull/1714#event-4947041362
On Mon, 28 Jun 2021, 18:32 Jonathan Fine, wrote:
> Thomas Grainger wrote:
>
> It looks like there's a consensus being reached, should I create a bpo?
>>
&
> but in this case the object is security sensitive, and security should be
> much more rigorous in ensuring correctness.
It looks like there's a consensus being reached, should I create a bpo?
Thomas Grainger
On Sat, 26 Jun 2021 at 23:03, Ethan Furman wrote:
>
> On 6/26/21 1:55 PM
I'd prefer a frozen dataclass with an explicit replace method
On Sat, 26 Jun 2021, 21:56 Marc-Andre Lemburg, wrote:
> On 26.06.2021 21:32, Ethan Furman wrote:
> > On 6/25/21 5:20 PM, Eric V. Smith wrote:
> >
> >> It seems like many of the suggestions are SSLContext specific. I don't
> think
> >
And it's on Python stdlib 3
https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool
On Sat, 26 Jun 2021, 17:24 Thomas Grainger, wrote:
> billiard a multiprocessing py2 fork/backport has
> https://billiard.readthedocs.io/en/latest/library/multiprocessin
billiard a multiprocessing py2 fork/backport has
https://billiard.readthedocs.io/en/latest/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool
with maxtasksperchild
On Sat, 26 Jun 2021, 16:57 Ram Rachum, wrote:
> Hi guys,
>
> I want to have a version of
How about an alternative frozen dataclass with a explicit replace,
configure and create methods?
@dataclasses.dataclass(frozen=True)
class SSLContextFactory:
minimum_version: TLSVersion = TLSVersion.TLSv1_2
options: ...
replace = dataclasses.replace
def configure(self, ctx:
I was debugging some code that was using TLSv1.2 when I expected it to only
support TLSv1.3, I tracked it down to a call to:
context.miunimum_version = ssl.TLSVersion.TLSv1_3
it should have been:
context.minimum_version = ssl.TLSVersion.TLSv1_3
I'd like invalid attribute assignment to be
It seems odd that it would be per module and not per scope?
On Tue, 22 Jun 2021, 00:55 Soni L., wrote:
>
>
> On 2021-06-21 8:42 p.m., Steven D'Aprano wrote:
> > On Mon, Jun 21, 2021 at 02:54:52PM -0300, Soni L. wrote:
> >
> > > Quite the opposite. You ask the local module (the one that the code
https://github.com/agronholm/anyio/blob/9eb4671547b01f5e3ba0e0ca602b6aceec15af86/src/anyio/_backends/_asyncio.py#L598
On Sat, 29 May 2021, 20:24 André Roberge, wrote:
>
>
> On Sat, May 29, 2021 at 3:25 PM Thomas Grainger wrote:
>
>> pytest uses __tracebackhide__
>>
&
pytest uses __tracebackhide__
https://doc.pytest.org/en/latest/example/simple.html#writing-well-integrated-assertion-helpers
Eg anyio sets __tracebackhide__ = __traceback_hide__ = True to remove
internal frames from user Tracebacks
On Sat, 29 May 2021, 19:21 André Roberge, wrote:
> With
This is already available with typing.Final and immutable types:
from typing import Final
ham: Final = 3
ham = 4 # Error
hams: Final[Sequence[str]] = ["ham", "spam"]
hams.append("meat") # Error
On Mon, 24 May 2021, 18:40 Abdur-Rahmaan Janhangeer,
wrote:
> Greetings,
>
> Just a light-hearted
seems a bit like https://www.python.org/dev/peps/pep-0505/
eg `d?[1]?[0]`
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
sounds very much like https://www.python.org/dev/peps/pep-0463/#rejection-notice
I'm concerned with the `safe` defaulting to a bare `except:` which will also
catch CancelledError other errors that should be re-raised
also
```
file = safe open('some_file')
```
does not provide a way to
how about:
```
try:
...
except E1 | E2 | E3 as e:
...
```
it's syntactically valid but is this again: https://bugs.python.org/issue12029
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to
now that python2.7 is EOL, it might be worth resurrecting this syntax as
discussed in https://www.python.org/dev/peps/pep-3100/#id13
eg, python 3.11 could support
```
try:
...
except (E1, E2, E3) as e:
...
```
as equivalent to
```
try:
...
except E1, E2, E3 as e:
...
```
see
> As another data point, flit *requires* that the package has a
> __version__ attribute.
flit no longer requires packages support `__version__` when using PEP 621
metadata
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an
I prefer to use importlib.metadata.version("dist-name")
On Mon, 12 Apr 2021, 19:51 Christopher Barker, wrote:
> Over the years, I've seen __version__ used very broadly but not *quite* in
> all packages. I've always known it was a convention, not a requirement. But
> it turns out it's not even a
map and filter are already available as comprehension syntax
However zip and merge are tricky because you'd need to schedule all
`__anext__()` coroutines from all input AsyncIterables. The stdlib would need
to know how to spawn tasks in such a way they could be understood by the
framework that
65 matches
Mail list logo