I suspect you wouldn't have to test it all, as it would simply be a trivial
redistribution of a standard (already known-good) generator:
def random_bit_666():
return int(random() > 2/3)
For other more sophisticated distributions, again simply verify that your
distribution algorithm is correct
I liked your idea so much back when you suggested it that I implemented it
in our sitecustomize.py back when we were using 3.8, and added a check to
our lint tools to require that the 'strict=' parameter be present in all
uses of 'zip'. We found a couple of silent bugs almost immediately, so
thank
On Tue, May 31, 2022 at 5:54 AM fjwillemsen--- via Python-ideas <
python-ideas@python.org> wrote:
> I can not think of good reasons why Python array multiplication should not
> throw an error for negative multipliers, because it is meaningless to have
> array multiplication by negative value in th
On Tue, Apr 5, 2022 at 7:49 AM Greg Ewing
wrote:
>
> It's only there now for backwards compatibility. It's not
>
Not always. I have an example, where a method creates a closure that calls
super, requiring the class/self pair as there isn't enough context for
parameterless super. (And also in _
My first thought was that this is a job for string.Template, which has
always struck me as subclassing-friendly. Took about a half hour of
wrangling the regex to get here:
from string import Template, _sentinel_dict
class TemplateWithDefaults(Template):
braceidpattern = r'([_a-z][_a-z0-9]*)
Most importantly, static type checking is still immature and as yet there
is no standard for how to say "this thing is an X". Adding type hints into
the stdlib source would force you to choose one (third party) tool,
https://typing.readthedocs.io/en/latest/#type-checkers , which then would
lock yo
As you probably suspect, yes, it comes up every couple of years. Here's
one of the recent threads (there are more, just search for 'until' in the
archives), that might give you some ideas for how this discussion will
progress. :)
https://mail.python.org/archives/list/python-ideas@python.org/threa
On Sun, 13 Feb 2022 at 15:43, Chris Angelico wrote:
> > it to. If I'm on Windows and I tell something to write to a file in
> > "%TEMP%\spam.csv", then I expect it to understand what that means.
> > Cross-platform support is nice, but the most common need is for the
> > current platform's normal
Yeah, I have to agree with Neil. I had exactly this issue a couple years
ago, and it took me an hour or two to figure out that it was a
property/descriptor-protocol causing the issue, at which point the fix
became trivial. Just knowing to think "it's a property, stupid!" was the
hard part and jus
On Tue, Oct 19, 2021 at 12:31 AM Tom Pohl wrote:
> I am aware of requests (or httpx, ...), but the idea is to do all that
> with the
> standard library. If I have to install stuff, I could just install
> wget/curl and be done.
>
I believe what you are looking for is already in the stdlib, see
ur
On Mon, Oct 11, 2021 at 8:08 PM Steven D'Aprano wrote:
> I assume you're not just extracting the first value for the LOLs, you
> must have some reason for it. It is *that reason* which counts as a
> use-case.
>
I dug through our application code base (500k lines) and found just one use
case of t
I'm somewhat confused by the term "last item of the set", as sets are not
ordered and have no "last" element:
>>> {1,3,3,2}
{1, 2, 3}
On Sat, Oct 2, 2021 at 8:23 PM Abdulla Al Kathiri <
alkathiri.abdu...@gmail.com> wrote:
> Then use it with the normal expression lambda:
> people.sort(key=p => (p
On Wed, Sep 15, 2021 at 12:21 AM Eric V. Smith wrote:
> And I'm not crazy about the name "workdir". To me, it sounds like it
> returns something, not sets and resets something. But I don't have a
> particularly great alternative in mind: in my own code I've used
> "change_dir", which isn't awesom
On Wed, Nov 25, 2020 at 3:44 PM Steven D'Aprano wrote:
> Obviously you can tell the two apart, so I'm confused by your comment.
>
What I imagined while reading Greg's comment was trying to explain to a
student why this didn't work the way they expected. "Ok, so in the first
case I'm *not* start
On Sat, Aug 22, 2020 at 7:37 AM wrote:
> No. I wanted to know if they can add this suggestion in next versions
>
That will not happen. You may want to familiarize yourself with the intent
of type annotations:
https://www.python.org/dev/peps/pep-0526/#non-goals
https://www.python.org/dev/peps/pe
Yeah, but "not a number of pounds" sure beats seeing "£inf".
On Thu, Jul 9, 2020 at 3:25 AM Jonathan Fine wrote:
> Off topic: I saw this NaN article this morning.
>
> Title: Hungry? Please enjoy this delicious NaN, courtesy of British Gas
> and Sainsbury's
> URL: https://www.theregister.com/2020
On Wed, May 6, 2020 at 6:27 PM David Mertz wrote:
> I don't think being a function versus a classmethod is important here.
> Just that the underlying name is *callable*.
>
But wait a minute, zip isn't just a "callable", it's a class, and adding
more methods to it seems perfectly natural, just li
On Sun, Apr 26, 2020 at 9:46 AM Alex Hall wrote:
> It's not clear to me why people prefer an extra function which would be
> exactly equivalent to lru_cache in the expected use case (i.e. decorating a
> function without arguments). It seems like a good way to cause confusion,
> especially for beg
On Wed, Apr 22, 2020 at 12:23 PM David Mertz wrote:
> On Wed, Apr 22, 2020, 4:24 AM Antoine Pitrou
>
>> But, as far as I'm concerned, the number of times where I took
>> advantage of zip()'s current acceptance of heteregenously-sized inputs
>> is extremely small. In most of my uses of zip(), a s
On Sat, Apr 11, 2020 at 4:21 AM Rhodri James wrote:
> Since the introduction of enumerate() lo! these many moons ago, I find I
> almost never write range(len(x)) as a loop iterable.
>
Out of curiosity, I just grepped about 300k lines of source:
234 - enumerate() in for loops
140 - zip() in for
On Fri, Apr 10, 2020 at 2:56 PM Serhiy Storchaka
wrote:
> Don't listen to anyone. There is only one obvious way to write this in
> one line:
>
> count = +(lambda *a: a[0](*a))((lambda q, r, s, i: r(r, q, s, i, next(i,
> s))), (lambda r, q, s, i, x: x is not s and (x in seek) + q(q, r, s,
> i)), [
On Wed, Mar 4, 2020 at 2:58 AM Steven D'Aprano wrote:
> I don't know enough about the Python internals to give a definitive
> answer, but I'm assuming/hoping that there is a single, or at most a
> few, places in the interpreter that matches up arguments to formal
> parameters, and if there's a di
I had just started to play with Andrew's code on Friday, but got distracted
by real work and had to drop it. This gets me further into the parts I
wanted to play with, so big thanks!
On Sun, Feb 23, 2020 at 5:45 AM André Roberge
wrote:
> (Apologies if this appears twice: I attempted to create a
On Thu, Dec 26, 2019 at 7:58 PM Marco Sulla via Python-ideas <
python-ideas@python.org> wrote:
>
> So 200 posts for one line less? I really don't catch the point.
>
You apparently did not read the posts, because the point was whether it
raises or returns a default value, not whether it saves one
My little experiments in 3.7 show exception setup is about 40% more costly
than just a do-nothing loop, but execution of is about 9x more expensive
than doing nothing, so actually very little cost if your loop only rarely
catches the exception (I assume you'll probably actually do something
inside
On Wed, Nov 13, 2019 at 2:09 PM Sebastian Kreft wrote:
> What Eric Fahlgren wants is basically the deprecated contextlib.nested
> function, that function should have the right semantics. See
> https://github.com/python/cpython/blob/2.7/Lib/contextlib.py#L88-L129
>
Oh, no, I don'
On Wed, Nov 13, 2019 at 11:26 AM MRAB wrote:
> "with" expression ["as" name] ":"
>
> but the expression itself can start with a parenthesis, so if it saw a
> parenthesis after the "with" it would be ambiguous
>
I have used 'with' for so long that I was under the impression that the
as-targe
On Mon, Jul 29, 2019 at 2:58 PM Guido van Rossum wrote:
> I am *guessing* the problem here is something like this:
>
> with open(filename) as f:
> data = f.read()
>
> raises an exception if the open() call fails, but putting try... except
> IOError: ... around the whole thing also catches I/O
On Mon, Apr 1, 2019 at 7:50 AM Antoine Pitrou wrote:
>
> And 01 / 04 / 2019 should return a April 1st datetime.
>
> (except in the US, of course)
>
Where it would of course be I / / MMXV, unless you have ISO-8601
set in which case it would be MMXV - - I
On Mon, Mar 18, 2019 at 7:04 AM Rhodri James wrote:
> On 18/03/2019 12:19, Richard Damon wrote:
> > On 3/18/19 7:27 AM, Greg Ewing wrote:
> >> Juancarlo Añez wrote:
> >>
> >>> if settings[MY_KEY] is True:
> >>> ...
> >>
> >> If I saw code like this, it would take a really good argumen
On Sun, Feb 3, 2019 at 7:57 AM James Lu wrote:
>
> This kind of readability issue, datetime.now, is an example of what’s
> contributing to Python’s decline.
>
Python's decline??? https://pypl.github.io/PYPL.html
___
Python-ideas mailing list
Python-id
My intuition has always been that the recipes, taking 'flatten' as an
excellent example, solve problems in a specific way that is not generally
considered to be the "right" way. For example, should 'flatten' perform
one-level flattening or deep recursive flattening? Should it handle
strings as si
On Wed, Oct 31, 2018 at 2:42 AM Chris Angelico wrote:
>
> https://www.python.org/dev/peps/pep-0463/ wants to say hi.
>
>
That was exactly my reaction, too, and usually is whenever one of these
"add a default" or similar ideas pops up. 463 should be re-examined, I was
very hopeful when it went th
Done https://github.com/python/mypy/issues/5775
On Thu, Oct 11, 2018 at 1:47 PM Ivan Levkivskyi
wrote:
> On Tue, 9 Oct 2018 at 15:17, Eric Fahlgren wrote:
>
>> On Tue, Oct 9, 2018 at 3:16 AM Ivan Levkivskyi
>> wrote:
>>
>>> class PathLike(Protocol[AnyStr])
On Tue, Oct 9, 2018 at 3:16 AM Ivan Levkivskyi wrote:
> class PathLike(Protocol[AnyStr]):
>
I had been working on this same problem intermittently for several months,
so thanks, but...
error: Invariant type variable 'AnyStr' used in protocol where
covariant one is expected
is called out on
On Wed, Aug 29, 2018 at 3:07 PM Marko Ristin-Kaufmann <
marko.ris...@gmail.com> wrote:
> Could you please elaborate a bit? I don't see how the annotations would
> make the contracts invoked on inheritance. Consider this simple case:
>
> class A:
> @icontract.pre(lambda x: x > 0)
> def some
How about just
https://homepages.cwi.nl/~storm/teaching/reader/Dijkstra68.pdf
On Wed, Aug 15, 2018 at 5:38 PM David Mertz wrote:
> Hmm.. link broke. Is this right?
>
>
> https://www.google.com/url?sa=t&source=web&rct=j&url=https://homepages.cwi.nl/~storm/teaching/reader/Dijkstra68.pdf&ved=2ahUKE
On Fri, Aug 3, 2018 at 6:19 PM Steven D'Aprano wrote:
> It needs some work. Something like "Here's an example in the standard
> library. On converting it to none-aware version, we realised the std lib
> version is buggy, because ...". A couple of sentences.
>
Yup, that's what I was getting at...
On Fri, Aug 3, 2018 at 5:26 PM Abe Dillon wrote:
> One last thing:
>
> Since expressions tend to have pretty limited space, it might be worth it
> to consider more concise options like maybe instead of:
>
> except (Exception[-list])[ as e]):
>
You're reinventing PEP 463:
https://www.python.or
On Thu, Aug 2, 2018 at 10:06 PM Alexandre Brault
wrote:
> I would make the opposite argument and claim that since when policy is
> None mangle_from_ is initialised to True and not None, None is likely not a
> potential value for policy.mangle_from_. Looking at
> Lib/email/_policybase.py where the
On Thu, Aug 2, 2018 at 3:39 PM MRAB wrote:
> In the relevant code, is policy.mangle_from_ ever None?
>
That's impossible to know, since the initializer where this code originally
appears puts no constraints on the value of 'policy', it's just assumed to
have a 'mangle_from_' member... I would b
On Thu, Aug 2, 2018 at 1:22 PM MRAB wrote:
> > policy?.mangle_from_ ?? True
> > True (??? since lhs is None?)
> >
> No, it's not 'policy.mangle_from_' that could be None, it's 'policy'
> that could be None (i.e. there's no policy).
>
In my example, there is a policy, and the value of policy.mang
>From the PEP:
>
>From email/generator.py (and importantly note that there is no way to
substitute or for ?? in this situation):
>
mangle_from_ = True if policy is None else policy.mangle_from_
> After updating:
>
mangle_from_ =
policy?.mangle_from_ ?? True
I cannot see how these are equivalent, a
On Thu, Jul 19, 2018 at 7:01 AM Calvin Spealman wrote:
> As an alternative suggestion: What if the count parameter to str.replace()
> counted from the right with negative values? That would be consistent with
> other things like indexing and slicing.
>
That could certainly be made to work, but
On Thu, Jul 19, 2018 at 6:52 AM Michael Hall
wrote:
> While I am aware of projects like Cython and mypy, it seems to make sense
> for CPython to allow optional enforcement of type hints, with compiler
> optimizations related to it to be used. While this would not receive the
> same level of perfo
On Wed, Jul 18, 2018 at 8:20 PM Graham Gott
wrote:
>
> Thoughts? Support/oppose?
>
+1, along with an overall rework of str methods to make them more
consistent.
The find, replace and split families should all gain the same
tuple-as-search-string that endswith and startswith use. (Discussed i
I've been getting those, too, but from the wxPython-dev group. I concur
that they look like googlegroups bounces (although I can't confirm that as
I've been deleting them without much inspection).
On Thu, Jun 28, 2018 at 9:35 AM Chris Barker via Python-ideas <
python-ideas@python.org> wrote:
> H
On Thu, Jun 14, 2018 at 4:03 AM Daniel Sánchez Fábregas
wrote:
> My idea consist in:
> Adding a method to perform type checking in traceback objects
> When printing stack traces search for mistyped arguments and warn about
> them to the user.
>
Isn't it faster and far more reliable to run your
On Wed, Jun 13, 2018 at 3:54 PM MRAB wrote:
> Would it check first-to-last or longest-to-shortest? I think that
> longest-to-shortest would be the most useful.
>
> >>> old = ('cat', 'cats')
> >>> new = ('mouse', 'mice')
> >>>
> >>> # First-to-last.
> >>> 'cats'.replace(old, new)
> 'mouses'
>
On Thu, May 31, 2018 at 10:55 PM Greg Ewing
wrote:
> Ethan Furman wrote:
>
> > Why is this? Doesn't the exception have to be instantiated at some
> > point, even if just to print to stderr?
>
> If it gets caught by an except clause without an else clause,
> in theory there's no need to instantia
On Tue, May 29, 2018 at 10:17 AM Barry Scott wrote:
> On Tuesday, 29 May 2018 16:42:13 BST Eric Fahlgren wrote:
>
> Maybe you are suffering from TCP windows scaling not work well enough?
>
Thanks for the tip, I'll have to mention that to our IT infrastructure guys
and see if
I have been doing speed testing on our network frequently enough over the
last five year that I have a good feel for these changes. I have been
benchmarking various means for copying files of 1.0-500 MB between
workstations on our 1 Gbps LAN to local servers, and on our WAN which was
just upgraded
On Tue, May 15, 2018 at 10:11 PM Rob Speer wrote:
> From what I can tell, if you wanted to exclude '__init__.py' from Nginx in
> particular, you would have to write an unconventional Nginx configuration,
> where you determine whether a path refers to a static file according to a
> regex that excl
On Sun, May 13, 2018 at 11:20 AM Guido van Rossum wrote:
> For example, we could allow keywords after 'def' and after a period, and
> then the following would become legal:
>
Our modeling database overloads getattr/setattr (think SQLAlchemy) to
allow us to access to database fields as if they w
On Tue, May 8, 2018 at 2:31 AM, Oleg Broytman wrote:
>So anyone who wants to filter os.walk() must reimplement os.walk()
> themselves instead of passing something like filter_dir and filter_file
> (or accept_dir/accept_file) to os.walk()? Kind of painful, no?
>
Not really. It's pretty simp
On Sun, May 6, 2018 at 9:30 PM, Mike Miller
wrote:
> On 2018-05-06 19:13, Nick Coghlan wrote:
>
>> Specifically, the ones I'd have in mind would be:
>>
>> - dirname (aka os.path.dirname)
>> - joinpath (aka os.path.join)
>> - abspath (aka os.path.abspath)
>>
> Yes, I end up importing those in most
On Tue, May 1, 2018 at 8:04 AM, Jacco van Dorp wrote:
> 2018-05-01 14:54 GMT+02:00 Greg Ewing :
> > Rhodri James wrote:
> >>
> >> I'd be interested to know if there is a readability difference between
> >> really_long_descriptive_identifier_name and
> >> ReallyLongDescriptiveIdentifierNames.
> >
On Sat, Apr 28, 2018 at 4:27 AM, Steven D'Aprano
wrote:
> On Fri, Apr 27, 2018 at 06:27:44AM -0700, Eric Fahlgren wrote:
>
> > I've had a 'dprint' in sitecustomize for years. It clones 'print' and
> adds
> > a couple of keyword parameters,
I've had a 'dprint' in sitecustomize for years. It clones 'print' and adds
a couple of keyword parameters, 'show_stack' and 'depth', which give
control over traceback output (walks back up sys._getframe for 'depth'
entries). It returns the final argument if there is one, otherwise None.
It can be
On Mon, Apr 16, 2018 at 10:23 AM, Brett Cannon wrote:
>
>
> On Mon, 16 Apr 2018 at 09:58 Eric Fahlgren wrote:
>
>> The documentation is pretty opaque or non-existent on other aspects of
>> importlib use, too.
>>
>
> Well, we are diving into the dark cor
The documentation is pretty opaque or non-existent on other aspects of
importlib use, too. If I enable warnings, I see this (and many more like
it). I've read PEP 302 a couple times, read the code in importlib that
detects the warning and searched down several rabbit holes, only to come up
empty.
On Tue, Apr 10, 2018 at 5:03 PM, Steven D'Aprano
wrote:
>
> __pycache__/spam.cpython-38.pyc
> __pycache__/spam.cpython-38-doc.pyc
> __pycache__/spam.cpython-38-lno.pyc
> __pycache__/spam.cpython-38-ann.pyc
>
Our product uses the doc strings for auto-generated help, so we need to
On Fri, Apr 6, 2018 at 7:47 AM, Peter O'Connor
wrote:
> 3) The idea that an assignment operation "a = f()" returns a value (a) is
> already consistent with the "chained assignment" syntax of "b=a=f()" (which
> can be thought of as "b=(a=f())"). I don't know why we feel the need for
> new constru
On Tue, Mar 27, 2018 at 9:52 AM, Paul Moore wrote:
> I'd actually like to see some real world use cases to get a feel for
> whether this is even worth worrying about. (I'm not saying it isn't,
> just that it's hard to get a feel for the importance based on
> artificial examples).
>
The only rea
On Sat, Mar 24, 2018 at 7:14 AM, Nick Coghlan wrote:
>
> >>> class C:
> ... sequence = range(10)
> ... listcomp = [x for x in sequence]
>
>>> class C:
... y = 1
... sequence = range(10)
... listcomp = [x+y for x in sequence]
...
Traceback (most recent call l
On Mon, Mar 19, 2018 at 9:59 AM, Terry Reedy wrote:
> I am convinced that *some* people, especially but not limited to newbies,
> find the current situation confusing and less than optimal. I am also
> pretty convinced that the idea of dumping a copy of everything into pathlib
> is the wrong sol
On Fri, Mar 2, 2018 at 12:20 PM, Chris Angelico wrote:
> How often do you have a loop like this where you actually want to
> capture the exact condition? I can think of two: regular expressions
> (match object or None), and socket read (returns empty string on EOF).
> This simplified form is ONLY
On Fri, Mar 2, 2018 at 10:27 AM, Jelle Zijlstra
wrote:
>
> I wonder if we could have a more limited change to the language that would
> allow only the as/while use cases. Specifically, that means we could do:
>
> while do_something() as x:
> print(x)
>
The "while" case is the only part of t
On Tue, Feb 6, 2018 at 6:47 AM, Paul Moore wrote:
> There are a few different points here:
>
> 1. There's no relationship between pip and the py launcher - they are
> separate tools/projects. Any co-operation in terms of file locations
> would have to be a result of common standards. Those would
My only request for change would be to consolidate the various tools'
behavior wrt their .ini file locations. Pip, for example, wants the file
in ~/pip/pip.ini, while py.exe (on Windows) wants its py.ini in
$LOCALAPPDATA. If they were all in a common location (or the same file
with separate secti
Could we call it "help"? Maybe add some beef to what's already there...
>>> help(lambda x,y,*args: x)
Help on function in module __main__:
lambda x, y, *args
On Thu, Dec 21, 2017 at 12:34 PM, Barry wrote:
>
>
> > On 21 Dec 2017, at 06:57, Chris Barker wrote:
> >
> > in theory, the "goal"
On Mon, Nov 20, 2017 at 1:59 PM, Chris Barker wrote:
> BTW -- does pip install a "pip3" on Windows?
>
In 3.6 it does:
> find t:/Python36/ -iname 'pip*exe'
t:/Python36/Scripts/pip.exe
t:/Python36/Scripts/pip3.6.exe
t:/Python36/Scripts/pip3.exe
_
On Wed, Jan 11, 2017 at 8:28 PM, Chris Barker wrote:
> Many of the things people (newbies, mostly) complain about are simply
> taste, or legacy that isn't worth changing.
>
A lot of that sort of thing is idiomatic, so I point people here and say
"just do it that way and you'll be happier in the
73 matches
Mail list logo