[Python-ideas] Re: Make filter() and map() return function if iterable is not passed

2021-02-11 Thread Chris Angelico
On Fri, Feb 12, 2021 at 1:01 AM Henry Harutyunyan wrote: > this is fine as long as you need to use that filter for once. But if you want > to reuse it you either need to create the iterator every time specifying the > filter function, or save the function in a var and create the filter with > t

[Python-ideas] Re: class(obj) could return obj.__class__

2021-02-08 Thread Chris Angelico
On Tue, Feb 9, 2021 at 6:39 PM Hans Ginzel wrote: > > Please, consider class(obj) to return obj.__class__ > consistenly with dir(), vars(), repr(), str(),… > > >>> class c: pass > >>> o = c() > >>> o.__class__ > > >>> class(o) >File "", line 1 > class(o) > ^ > SyntaxError: inva

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread Chris Angelico
On Mon, Feb 8, 2021 at 6:04 PM David Mertz wrote: > > There's a reason that never in the last 3800 years since Proto-Sinaitic was > the first human script to approximately represent phonemes, has text EVER > been set at more than 80 characters as a widespread convention. > What did they use as

[Python-ideas] Re: [Python-Dev] Re: What's up with assignment expression and tuples?

2021-02-07 Thread Chris Angelico
t; > > > try: > > > return a_dict[key] > > > except KeyError: > > > return (a_dict[key] := expression to construct value) > > On Sat, Feb 6, 2021, at 01:26, Chris Angelico wrote: > > > > That's what the __missing__ method is

[Python-ideas] Re: [Python-Dev] Re: What's up with assignment expression and tuples?

2021-02-06 Thread Chris Angelico
On Sat, Feb 6, 2021 at 8:54 PM Paul Sokolovsky wrote: > > Hello, > > On Sat, 6 Feb 2021 17:26:00 +1100 > Chris Angelico wrote: > > > On Sat, Feb 6, 2021 at 5:21 PM Random832 > > wrote: > > > > > > While we're on the subject of assignment expr

[Python-ideas] Re: [Python-Dev] Re: What's up with assignment expression and tuples?

2021-02-05 Thread Chris Angelico
On Sat, Feb 6, 2021 at 5:21 PM Random832 wrote: > > While we're on the subject of assignment expression limitations, I've > occasionally wanted to write something like > > try: > return a_dict[key] > except KeyError: > return (a_dict[key] := expression to construct value) That's what the

[Python-ideas] Re: [Python-Dev] Re: What's up with assignment expression and tuples?

2021-02-05 Thread Chris Angelico
On Sat, Feb 6, 2021 at 6:08 AM Paul Sokolovsky wrote: > And looking back now, that seems like intentionally added accidental > gap in the language (https://en.wikipedia.org/wiki/Accidental_gap). > Similar to artificially limiting decorator syntax, which was already > un-limited. But seems, there'r

[Python-ideas] Re: Add lazy import statement to protect legitimate circular imports from failing

2021-02-05 Thread Chris Angelico
On Sat, Feb 6, 2021 at 12:51 AM Matt del Valle wrote: > > Unfortunately, [lazy importers are] fundamentally incapable of dealing with > 'from x import y' syntax, because this is always loaded eagerly by the Python > interpreter. > This is because it's fundamentally hard. > With the increasingl

[Python-ideas] Re: Add a couple of options to open()'s mode parameter to deal with common text encodings

2021-02-04 Thread Chris Angelico
On Fri, Feb 5, 2021 at 10:46 AM Ben Rudiak-Gould wrote: > > > > On Thu, Feb 4, 2021 at 3:29 PM Chris Angelico wrote: >> >> With "t", it takes/gives Unicode objects, but with "b" it uses bytes. > > > Sure, in Python 3, but not in Python 2, or

[Python-ideas] Re: Add a couple of options to open()'s mode parameter to deal with common text encodings

2021-02-04 Thread Chris Angelico
On Fri, Feb 5, 2021 at 10:17 AM Ben Rudiak-Gould wrote: > 'L' could be argued to be unnecessary if there's a simple way to achieve the > same thing with the encoding parameter (which currently there isn't). > I'd rather work that one out the opposite way, having encoding="locale" (or encoding="s

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-24 Thread Chris Angelico
On Mon, Jan 25, 2021 at 3:55 AM Stephen J. Turnbull wrote: > > Chris Angelico writes: > > Right, but as long as there's only one system encoding, that's not > > our problem. If you're on a Greek system and you want to decode > > ISO-8859-9 text, you

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-24 Thread Chris Angelico
On Mon, Jan 25, 2021 at 12:33 AM Steven D'Aprano wrote: > > On Sat, Jan 23, 2021 at 03:24:12PM +, Barry Scott wrote: > > > I think that you are going to create a bug magnet if you attempt to auto > > detect the encoding. > > > > First problem I see is that the file may be a pipe and then you w

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-24 Thread Chris Angelico
On Sun, Jan 24, 2021 at 9:13 PM Stephen J. Turnbull wrote: > > Chris Angelico writes: > > > Can anyone give an example of a current in-use system encoding that > > would have [ASCII bytes in non-ASCII text]? > > Shift JIS, Big5. (Both can have bytes < 128 insi

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-23 Thread Chris Angelico
On Sun, Jan 24, 2021 at 2:46 PM Matt Wozniski wrote: > 2. At the same time as the deprecation is announced, introduce a new > __future__ import named "utf8_open" or something like that, to opt into the > future behavior of `open` defaulting to utf-8-sig or utf-8 when opening a > file in text mo

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-23 Thread Chris Angelico
On Sun, Jan 24, 2021 at 2:31 AM Barry Scott wrote: > I think that you are going to create a bug magnet if you attempt to auto > detect the encoding. > > First problem I see is that the file may be a pipe and then you will block > until you have enough data to do the auto detect. > > Second problem

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-23 Thread Chris Angelico
On Sat, Jan 23, 2021 at 11:34 PM Stephen J. Turnbull wrote: > > I'd rather focus on just moving to UTF-8 as the default, rather > > than bringing in a new function - especially with such a confusing > > name. > > I expect there are several bodies of users who will experience that as > quite obn

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-23 Thread Chris Angelico
On Sat, Jan 23, 2021 at 9:04 PM Inada Naoki wrote: > > On Sat, Jan 23, 2021 at 10:47 AM Chris Angelico wrote: > > > > > > Highly dubious. I'd rather focus on just moving to UTF-8 as the > > default, rather than bringing in a new function - especially with such

[Python-ideas] Re: Adding `open_text()` builtin function. (relating to PEP 597)

2021-01-22 Thread Chris Angelico
On Sat, Jan 23, 2021 at 12:37 PM Inada Naoki wrote: > ## 1. Add `io.open_text()`, builtin `open_text()`, and > `pathlib.Path.open_text()`. > > All functions are same to `io.open()` or `Path.open()`, except: > > * Default encoding is "utf-8". > * "b" is not allowed in the mode option. I *really* d

[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Chris Angelico
On Fri, Jan 22, 2021 at 11:48 AM Neil Girdhar wrote: > If enumerate(some_sequence) returns a sequence view, iterating over > that sequence view does not advance it—just like how DictViews are not > altered by iteration. Same thing if reversed(some_sequence) returns a > sequence view. Then that's

[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Chris Angelico
On Fri, Jan 22, 2021 at 11:10 AM Random832 wrote: > > On Thu, Jan 21, 2021, at 18:48, Chris Angelico wrote: > > Note that slicing is NOT easy. The proposed semantics for a reversed > > enumeration would make slicing extremely odd. > > What proposed semantics? You were t

[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Chris Angelico
On Fri, Jan 22, 2021 at 8:31 AM Neil Girdhar wrote: > It's possible for reversed(enumerate(...)) to just work if enumerate > of a sequence were to return a sequence view. Then you would also get > all the other sequence operations for free like enumerate(...)[23:27], > len(enumerate(...)), etc.

[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Chris Angelico
On Fri, Jan 22, 2021 at 5:44 AM Neil Girdhar wrote: > > On Thu, Jan 21, 2021 at 1:26 PM Chris Angelico wrote: > > > > On Fri, Jan 22, 2021 at 5:21 AM Neil Girdhar wrote: > > > > > > I've seen this proposed here before. The general idea is that s

[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Chris Angelico
On Fri, Jan 22, 2021 at 5:21 AM Neil Girdhar wrote: > > I've seen this proposed here before. The general idea is that some iterator > transformations (like enumerate) should return sequences when they're applied > to sequences. I think it's good idea, but it adds complexity and work, which >

[Python-ideas] Re: Python with braces formal proposal?

2021-01-18 Thread Chris Angelico
On Tue, Jan 19, 2021 at 8:58 AM Random832 wrote: > > On Tue, Jan 5, 2021, at 17:17, lasizoillo wrote: > > Sorry, but if I'm understanting the point is to make one-liners. For > > example, if I want to do something like: > > > > $ env | grep "^XDG" > > > > In one python one liner like > > > > $ pyt

[Python-ideas] Re: Best practices of class "reopening" a-la Ruby?

2021-01-14 Thread Chris Angelico
On Thu, Jan 14, 2021 at 10:07 PM Paul Sokolovsky wrote: > The question then: what are the best practices in *declarative* syntax > to achieve the same effect in Python? (but of course, unlike Ruby, > there should be explicit syntactic marker that we augment existing > class, not redefine it). Eas

[Python-ideas] Re: timeit improvement idea: add an option to measure a script execution time

2021-01-10 Thread Chris Angelico
On Mon, Jan 11, 2021 at 6:06 AM Paul Moore wrote: > > On 2021-01-10 at 18:38:12 +0100, > Alex Prengère wrote: > > 3. Use timeit. The scripts have no side effects so repeating their > > execution the way timeit does, works for me. The only issue is that, > > as far as I know, timeit only allows st

[Python-ideas] Re: timeit improvement idea: add an option to measure a script execution time

2021-01-10 Thread Chris Angelico
On Mon, Jan 11, 2021 at 4:42 AM Alex Prengère wrote: > > Hello, > Today I had a quite simple need, I am unsure about the best way to do it, and > saw a possible improvement for the timeit module. > > I have about 30 Python scripts and I want to measure precisely their > execution times, without

[Python-ideas] Re: pathlib enhancements

2021-01-09 Thread Chris Angelico
On Sun, Jan 10, 2021 at 4:51 AM Stephen J. Turnbull wrote: > > Joseph Martinot-Lagarde writes: > > > One remark about this : .tar.gz files are the exception rather than > > the rule, and AFAIK maybe the only one ? > > Not really. stem.ext -> stem.ext.zzz where zzz is a compression > extension i

[Python-ideas] Re: Support reversed(itertools.chain(x, y, z))

2021-01-09 Thread Chris Angelico
On Sun, Jan 10, 2021 at 12:29 AM Oscar Benjamin wrote: > I haven't ever wanted to reverse a chain but I have wanted to be able > to reverse an enumerate many times: > > >>> reversed(enumerate([1, 2, 3])) > ... > TypeError > > The alternative zip(range(len(obj)-1, -1, -1), reversed(obj)

[Python-ideas] Re: Support reversed(itertools.chain(x, y, z))

2021-01-08 Thread Chris Angelico
On Sat, Jan 9, 2021 at 10:21 AM Steven D'Aprano wrote: > Not every trivial combination of functions needs to be given a built-in > or standard library solution. Especially not if doing so will break > backwards compatibility. > > "I had three numbers in a tuple, and wanted half of twice the first

[Python-ideas] Re: Python with braces formal proposal?

2021-01-07 Thread Chris Angelico
On Thu, Jan 7, 2021 at 9:12 PM Paul Sokolovsky wrote: > In that regard, as of 3.9, CPython, has absolutely atrocious REPL > support for its own syntax. It's just barely possible at all to type > multi-line statement, but doing that as painful as hell, and after > typing, editing is not possible. >

[Python-ideas] Re: Python with braces formal proposal?

2021-01-06 Thread Chris Angelico
On Wed, Jan 6, 2021 at 9:27 PM Steven D'Aprano wrote: > I'm glad that things like Perl one-liners, obfuscated C, and > sewerage treatment works exist... :) > Multi-statment anonymous functions are, in my opinion, overrated, and a > (slight) code smell. If your lambda is so complex it requires mo

[Python-ideas] Re: Python with braces formal proposal?

2021-01-05 Thread Chris Angelico
On Wed, Jan 6, 2021 at 9:17 AM lasizoillo wrote: > > Sorry, but if I'm understanting the point is to make one-liners. For example, > if I want to do something like: > > $ env | grep "^XDG" > > In one python one liner like > > $ python -c 'import os;print("\n".join([f"{key}:{value}" for key, value

[Python-ideas] Re: Python with braces formal proposal?

2021-01-05 Thread Chris Angelico
On Wed, Jan 6, 2021 at 12:01 AM Paul Sokolovsky wrote: > Anyway, this went offtopic wrt to the original subject. > [chomp loads of drivel] Yep, nothing more in this thread. Time to let it die a quiet death. ChrisA ___ Python-ideas mailing list -- pytho

[Python-ideas] Re: Python with braces formal proposal?

2021-01-05 Thread Chris Angelico
On Tue, Jan 5, 2021 at 9:38 PM Paul Sokolovsky wrote: > There were good reasons to not have string interpolation in the core > language for decades then - KABOOM - there's string interpolation. You > see a pattern yet? No? Oh, let's just keep watching. Do you have evidence from the language itsel

[Python-ideas] Re: Python with braces formal proposal?

2021-01-05 Thread Chris Angelico
On Tue, Jan 5, 2021 at 8:32 PM Paul Sokolovsky wrote: > And you seem to have 2nd level miss about this miss. I'm not the 1st > asking about braces in Python, hundreds of people embraced braces > (sorry for the pun) in Python for decades (references are in other > messages of this thread). Apparent

[Python-ideas] Re: Python with braces formal proposal?

2021-01-04 Thread Chris Angelico
On Tue, Jan 5, 2021 at 9:05 AM Steven D'Aprano wrote: > > On Mon, Jan 04, 2021 at 01:38:23PM +0300, Paul Sokolovsky wrote: > > Hello, > > > > There're tons of projects which introduce alternative braces > > (i.e. C-like) syntax for Python. > > Got any examples of these projects? Preferably ones th

[Python-ideas] Re: Add venv activate command to the venv modules

2021-01-04 Thread Chris Angelico
On Tue, Jan 5, 2021 at 2:37 AM Abdur-Rahmaan Janhangeer wrote: > > You just execute the appropriate shell commands via Python Try it. It won't work. See previous posts. ChrisA ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send

[Python-ideas] Re: Add venv activate command to the venv modules

2021-01-04 Thread Chris Angelico
On Tue, Jan 5, 2021 at 2:29 AM Abdur-Rahmaan Janhangeer wrote: > > Unfortunately, that wouldn't work. Activating a virtual environment > means setting some env vars in the current shell, and Python is > fundamentally unable to do that - it can only be done within the shell > itself (by sourcing a

[Python-ideas] Re: Add venv activate command to the venv modules

2021-01-04 Thread Chris Angelico
On Tue, Jan 5, 2021 at 1:52 AM Calvin Spealman wrote: > > > > On Mon, Jan 4, 2021 at 9:47 AM Chris Angelico wrote: >> >> On Tue, Jan 5, 2021 at 1:42 AM Abdur-Rahmaan Janhangeer >> wrote: >> > >> > Greetings list, >> > >> &g

[Python-ideas] Re: Add venv activate command to the venv modules

2021-01-04 Thread Chris Angelico
On Tue, Jan 5, 2021 at 1:42 AM Abdur-Rahmaan Janhangeer wrote: > > Greetings list, > > put simply, > > be able to use > > $ python -m venv venv_name activate > > To activate an env instead of having each platform have a way of > handling it > Unfortunately, that wouldn't work. Activating a virtua

[Python-ideas] Re: Python with braces formal proposal?

2021-01-04 Thread Chris Angelico
On Mon, Jan 4, 2021 at 9:41 PM Paul Sokolovsky wrote: > > Hello, > > There're tons of projects which introduce alternative braces > (i.e. C-like) syntax for Python. Most of them are however not properly > documented, and definitely not spec'ed for what they do. > > I wonder, does anyone here remem

[Python-ideas] Re: (Off-topic) Different object, same id

2021-01-01 Thread Chris Angelico
On Sat, Jan 2, 2021 at 7:56 AM Jonathan Fine wrote: > > Bravo, Jeff. I couldn't have chosen a better example. > > However, I'd expect large ints to be stored in two parts. A (class, pointer) > pair which has fixed size. And memory referenced by the pointer, large enough > to store the value of t

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-31 Thread Chris Angelico
On Thu, Dec 31, 2020 at 3:13 PM Brendan Barnwell wrote: > > On 2020-12-29 15:01, Christopher Barker wrote: > > along with a COMPLETE list of > > the language features that make use of that protocol. > > > > > > That is pretty much impossible -- that's kind of the point of a protocol > > --

[Python-ideas] Re: built in to clear terminal

2020-12-29 Thread Chris Angelico
On Wed, Dec 30, 2020 at 9:57 AM Mike Miller wrote: > Also, I'd argue the likelihood of a newbie clearing important work... is not > very high. > Disputed on the basis of having seen it all too often :) ChrisA ___ Python-ideas mailing list -- python-id

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Chris Angelico
On Wed, Dec 30, 2020 at 8:49 AM Brendan Barnwell wrote: > To my mind, every time a change is made to Python behavior there must > be a corresponding change to the main documentation describing the > change. I would go so far as to say that the lack of such documentation > updates should b

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-28 Thread Chris Angelico
On Mon, Dec 28, 2020 at 7:45 PM Anton Abrosimov wrote: > > Steven D'Aprano wrote: > > Why do you want something that isn't a mapping to be usable with mapping > > unpacking? > > I think mapping is not `abc.Mapping` class only. > > What about: > `Iterator[Tuple[str, int]]` > > ``` > @dataclass > cl

[Python-ideas] Re: str.isfloat()

2020-12-27 Thread Chris Angelico
On Mon, Dec 28, 2020 at 9:55 AM Joao S. O. Bueno wrote: > On Sun, 27 Dec 2020 at 19:31, Chris Angelico wrote: > Sorry, I thought my message conveyed that I know "float" exists, and > try/except is the current usable pattern (it is in the original posting > anyway) An

[Python-ideas] Re: str.isfloat()

2020-12-27 Thread Chris Angelico
On Mon, Dec 28, 2020 at 9:22 AM Joao S. O. Bueno wrote: > > I agree - the three builtin methods are almost the same (not sure if > there is any difference at all), Yes - they all check if the string matches a particular set of characters. > while there is no trivial way to check for a valid > fl

[Python-ideas] Re: built in to clear terminal

2020-12-26 Thread Chris Angelico
On Sun, Dec 27, 2020 at 4:26 PM Steven D'Aprano wrote: > > On Sun, Dec 27, 2020 at 02:00:00PM +1100, Chris Angelico wrote: > > > This is actually the exact part that I think should *not* happen, for > > several reasons: > > > > 1) Stuff that exists interactiv

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-26 Thread Chris Angelico
On Sun, Dec 27, 2020 at 4:30 PM Brendan Barnwell wrote: > That said. . . I'm starting to wonder why not just create a new dunder > called __items__ and have dict alias that to .items(). Then the > **-unpacking protocol could use that and everything would be fine, right? > +0.95. If we c

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-26 Thread Chris Angelico
On Sun, Dec 27, 2020 at 1:45 PM Greg Ewing wrote: > > On 27/12/20 3:03 pm, Chris Angelico wrote: > > But that would mean that a lot of iterables would look like mappings > > when they're not. > > In the context of ** you're expecting a mapping, not a sequence. &g

[Python-ideas] Re: built in to clear terminal

2020-12-26 Thread Chris Angelico
On Sun, Dec 27, 2020 at 1:25 PM Steven D'Aprano wrote: > But the ctrl-L trick has no discoverability. It took me close to twenty > years of using Linux before I discovered it, and I still don't remember > to use it when I need it. > > Beginners and casual users aren't going to know ctrl-L, or stum

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-26 Thread Chris Angelico
On Sun, Dec 27, 2020 at 1:15 PM Brendan Barnwell wrote: > > On 2020-12-26 18:03, Chris Angelico wrote: > > On Sun, Dec 27, 2020 at 11:36 AM Greg Ewing > > wrote: > >> > >> On 27/12/20 10:15 am, Christopher Barker wrote: > >> > It does seem like *

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-26 Thread Chris Angelico
On Sun, Dec 27, 2020 at 11:36 AM Greg Ewing wrote: > > On 27/12/20 10:15 am, Christopher Barker wrote: > > It does seem like ** could be usable with any iterable that returns > > pairs of objects. However the trick is that when you iterate a dict, you > > get the keys, not the items, which makes m

[Python-ideas] Re: fsync-on-close io object

2020-12-24 Thread Chris Angelico
On Fri, Dec 25, 2020 at 9:30 AM Steven D'Aprano wrote: > Perhaps a "sync on close" keyword argument to open? At least then it is > always available and easily discoverable. +1 (though this is really just bikeshedding) > > 3. There are many ways to do this, and I think several of them could > > b

[Python-ideas] Re: built in to clear terminal

2020-12-22 Thread Chris Angelico
On Wed, Dec 23, 2020 at 9:15 AM Steven D'Aprano wrote: > > On Mon, Dec 21, 2020 at 08:22:35AM +1100, Cameron Simpson wrote: > > >is it so bad to use a subprocess? > > > > Yes. It is _really slow_, depends on external reaources which might not > > be there, and subprocess brings other burdens too.

[Python-ideas] Re: Standalone bool?

2020-12-21 Thread Chris Angelico
On Tue, Dec 22, 2020 at 11:52 AM Christopher Barker wrote: > > On Mon, Dec 21, 2020 at 3:37 PM Greg Ewing > wrote: >> >> > However, that ship has sailed. I think it would have been minimally >> > disruptive when True and False were first introduced, >> >> It would have been just as disruptive ba

[Python-ideas] Re: Standalone bool?

2020-12-21 Thread Chris Angelico
On Tue, Dec 22, 2020 at 5:59 AM David Mertz wrote: > > On Mon, Dec 21, 2020 at 6:32 PM Chris Angelico wrote: >> >> But the real question is: Why do points compare equal based on their >> locations, if you need them to be independently stored in a set? >> Logical

[Python-ideas] Re: Standalone bool?

2020-12-21 Thread Chris Angelico
On Tue, Dec 22, 2020 at 5:20 AM David Mertz wrote: > > On Mon, Dec 21, 2020 at 5:56 PM Paul Bryan wrote: >> >> I'm interested in knowing when (id(x), x) would be preferable over (type(x), >> x). > > > Something along these lines: > > >>> class Point: > ... def __init__(self, x, y): > ...

[Python-ideas] Re: Standalone bool?

2020-12-21 Thread Chris Angelico
On Mon, Dec 21, 2020 at 7:15 PM Paul Bryan wrote: > > Hmm, I see ints, floats and decimal.Decimal all produce the same hashes for > integer values, so they also suffer the same fate in sets and dicts. > Yes, because they compare equal. (The hash is secondary to that.) Since 1 == 1.0, they must b

[Python-ideas] Re: Standalone bool?

2020-12-21 Thread Chris Angelico
On Mon, Dec 21, 2020 at 7:00 PM Paul Bryan wrote: > > I know this has come up in the past. > > Could the consensus have changed regarding bool's inheritance from int? > > This is not intuitive (to me), and recently bit me as a bug: > > Python 3.9.1 (default, Dec 13 2020, 11:55:53) > > [GCC 10.2.0]

[Python-ideas] Re: Using explicit parenthesization to convey aspects of semantic meaning?

2020-12-17 Thread Chris Angelico
On Fri, Dec 18, 2020 at 5:02 AM Paul Sokolovsky wrote: > This is not some completely new restriction. For example, following > already doesn't work in Python: > > class A: > pass > > o = A() > o.__add__ = lambda self, x: print("me called") > > o + A() # lambda above is never called > But the

[Python-ideas] Re: Using explicit parenthesization to convey aspects of semantic meaning?

2020-12-16 Thread Chris Angelico
On Thu, Dec 17, 2020 at 10:47 AM Greg Ewing wrote: > A feature of Prothon was that a.b() and t = a.b; t() would do > quite different things (one would pass a self argument and the > other wouldn't). > > I considered that a bad thing. I *like* the fact that in Python > I can use a.b to get a bound

[Python-ideas] Re: Using explicit parenthesization to convey aspects of semantic meaning?

2020-12-15 Thread Chris Angelico
On Wed, Dec 16, 2020 at 3:16 AM David Mertz wrote: > > On Tue, Dec 15, 2020 at 11:22 AM Chris Angelico wrote: >> I'm pretty sure most of us learned *in grade school* about BOMDAS or >> BODMAS or PEMDAS or whatever mnemonic you pick. > > I don't think I ever le

[Python-ideas] Re: Using explicit parenthesization to convey aspects of semantic meaning?

2020-12-15 Thread Chris Angelico
On Tue, Dec 15, 2020 at 9:22 PM Paul Sokolovsky wrote: > On Tue, 15 Dec 2020 20:17:37 +1100 > Chris Angelico wrote: > > > On Tue, Dec 15, 2020 at 8:04 PM Paul Sokolovsky > > wrote: > > > So, let's try simple yes/no questions: > > > > > &g

[Python-ideas] Re: Using explicit parenthesization to convey aspects of semantic meaning?

2020-12-15 Thread Chris Angelico
On Tue, Dec 15, 2020 at 8:49 PM Paul Sokolovsky wrote: > Right, and the question is what semantic (not implementational!) shift > happened in 3.7 (that's the point when it started to be compiled > differently). Have you read the release notes? https://docs.python.org/3/whatsnew/3.7.html#optimiza

[Python-ideas] Re: Using explicit parenthesization to convey aspects of semantic meaning?

2020-12-15 Thread Chris Angelico
On Tue, Dec 15, 2020 at 8:08 PM Paul Sokolovsky wrote: > > Hello, > > On Mon, 14 Dec 2020 02:17:52 -0500 > David Mertz wrote: > > > On Sun, Dec 13, 2020, 5:11 PM Paul Sokolovsky d > > > > > a + b + c vs a + (b + c) > > > > > > Here, there's even no guarantee of the same result, if we have use

[Python-ideas] Re: Using explicit parenthesization to convey aspects of semantic meaning?

2020-12-15 Thread Chris Angelico
On Tue, Dec 15, 2020 at 8:04 PM Paul Sokolovsky wrote: > So, let's try simple yes/no questions: > > Example 1: > > a + b + c vs a + (b + c) > > Question 1: > Do you agree that there's a clear difference between left and right > expression? Yes/no. Yes, there is a difference. > Example 2: > >

[Python-ideas] Re: Using explicit parenthesization to convey aspects of semantic meaning?

2020-12-13 Thread Chris Angelico
On Mon, Dec 14, 2020 at 5:57 PM Paul Sokolovsky wrote: > > But that's what the question was about, and why there was the intro! > Let's please go over it again. Do you agree with the following: > > a + (b + c) <=> t = b + c; a + t > > ? > > Where "<=>" is the equivalence operator. I do hope you

[Python-ideas] Re: Using explicit parenthesization to convey aspects of semantic meaning?

2020-12-13 Thread Chris Angelico
On Mon, Dec 14, 2020 at 9:11 AM Paul Sokolovsky wrote: > What would be the explanation for all that? > > > For reference, the disassembly of the 3 lines with CPython3.7 is > provided: > > 1 0 LOAD_NAME0 (obj) > 2 LOAD_METHOD 1 (meth) >

[Python-ideas] Re: Conditional with statements

2020-12-11 Thread Chris Angelico
On Sat, Dec 12, 2020 at 11:42 AM Jonathan Crall wrote: > > I'm not sure if this has been asked / suggested before. > > I'm wondering if there is any interest in conditional or loop-based `with` > statements. I think it could be done without a syntax change. > > ### Napkin proposal > > Context man

[Python-ideas] Re: An itertools.interleave / itertools.join function

2020-12-10 Thread Chris Angelico
On Fri, Dec 11, 2020 at 2:46 PM wrote: > > Here is an example of how I use it to build an arbitrary long SQL request > without having to pay for long intermediate strings, both in computation on > memory. > > from itertools import chain #, join > def join(sep, iterable): > notfir

[Python-ideas] Re: Proposal for __encode__ method for json encoder and dataclasses

2020-12-09 Thread Chris Angelico
On Thu, Dec 10, 2020 at 12:38 AM sam bland wrote: > > In response to the additional work required to convert the new python > dataclass using the json encoder I propose an __encode__ method that will be > included in the default dataclass attributes. This would then be picked up by > the defaul

[Python-ideas] Re: Thinking about dead simple import hooks...

2020-12-08 Thread Chris Angelico
On Tue, Dec 8, 2020 at 11:05 PM Paul Sokolovsky wrote: > > It'd be best to > > just write what you want directly, using the tools in importlib. > > Of course, the implementation of the above for CPython would be based on > importlib. And other implementations could implement that "directly", > for

[Python-ideas] Re: Thinking about dead simple import hooks...

2020-12-08 Thread Chris Angelico
On Tue, Dec 8, 2020 at 9:54 PM Paul Sokolovsky wrote: > > Hello, > > On Tue, 8 Dec 2020 07:29:15 -0300 > "Joao S. O. Bueno" wrote: > > > And how would Python compute the "full basename of the file to be > > imported"? > > The way it does it usually. > That involves a number of searches for exact

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Chris Angelico
On Fri, Dec 4, 2020 at 2:42 AM Jonathan Fine wrote: > > Hi > > On Thu, Dec 3, 2020 at 2:02 PM Chris Angelico wrote: >> >> well... uhhh Technically you can do that already >> >> for a in aaa: >> for b in bbb: >> if c

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Chris Angelico
On Fri, Dec 4, 2020 at 12:25 AM Jonathan Fine wrote: > > Hi Jonatan > > Please consider > for a in aaa: > for b in bbb: > if condition(a, b): > break > KEYWORD: > break > where KEYWORD is like else, but with the opposite semantics. I thin

[Python-ideas] Re: [RFC] "Strict execution mode" (TL;DR version)

2020-12-02 Thread Chris Angelico
On Wed, Dec 2, 2020 at 9:18 PM Steven D'Aprano wrote: > > That's "conceptual model". How it's actually implemented is, "bu abuse > > of notation" is: > > > > def decorate(func): > > ... > > > > Works without hitch with the strict mode. > > Okay, Chris made the same point. > > Is that a language gu

[Python-ideas] Re: Making the for statement work better with nested functions

2020-12-02 Thread Chris Angelico
On Wed, Dec 2, 2020 at 7:18 PM Paul Sokolovsky wrote: > > Hello, > > On Wed, 2 Dec 2020 18:39:42 +1100 > Chris Angelico wrote: > > > On Wed, Dec 2, 2020 at 6:37 PM Paul Sokolovsky > > wrote: > > > A sufficiently smart JIT is sufficiently hard to develop.

[Python-ideas] Re: [RFC] "Strict execution mode" (TL;DR version)

2020-12-02 Thread Chris Angelico
On Wed, Dec 2, 2020 at 7:24 PM Chris Angelico wrote: > > On Wed, Dec 2, 2020 at 7:11 PM Paul Sokolovsky wrote: > > > Python can't change its execution plans based on type > > > > CPython can't, other Pythons can. Mypyc is a well-known Python which > >

[Python-ideas] Re: [RFC] "Strict execution mode" (TL;DR version)

2020-12-02 Thread Chris Angelico
On Wed, Dec 2, 2020 at 7:11 PM Paul Sokolovsky wrote: > > Python can't change its execution plans based on type > > CPython can't, other Pythons can. Mypyc is a well-known Python which > changes its execution plans based on type annotations. "Mypyc is (mostly) not yet useful for general Python de

[Python-ideas] Re: Making the for statement work better with nested functions

2020-12-01 Thread Chris Angelico
On Wed, Dec 2, 2020 at 6:37 PM Paul Sokolovsky wrote: > A sufficiently smart JIT is sufficiently hard to develop. As an example, > a most well-known and most-used Python implementation, CPython, doesn't > have any JIT at all, not only "sufficiently advanced", but even > "simple". But simple would

[Python-ideas] Re: [RFC] "Strict execution mode" (TL;DR version)

2020-12-01 Thread Chris Angelico
On Wed, Dec 2, 2020 at 6:20 PM Paul Sokolovsky wrote: > > Hello, > > On Wed, 2 Dec 2020 00:10:41 +0100 > Marco Sulla wrote: > > > On Tue, 1 Dec 2020 at 23:49, Paul Sokolovsky > > wrote: > > > On Wed, 2 Dec 2020 09:16:56 +1100 > > > Chris Ange

[Python-ideas] Re: [RFC] "Strict execution mode" (TL;DR version)

2020-12-01 Thread Chris Angelico
On Wed, Dec 2, 2020 at 10:45 AM Steven D'Aprano wrote: > Is monkey-patching disallowed because `mod.func1` is defined as a > constant? Or are all functions automatically considered to be > constants? > > If the later, then decorators won't work in strict mode: > > @decorate > def func(): >

[Python-ideas] Re: [RFC] "Strict execution mode" (TL;DR version)

2020-12-01 Thread Chris Angelico
On Wed, Dec 2, 2020 at 9:10 AM Paul Sokolovsky wrote: > On Wed, 2 Dec 2020 03:02:26 +1100 > Chris Angelico wrote: > > If there are special-purpose cut-down implementations that provide a > > more restricted environment in return for some other feature (say, > > &qu

[Python-ideas] Re: [RFC] "Strict execution mode" (TL;DR version)

2020-12-01 Thread Chris Angelico
On Wed, Dec 2, 2020 at 2:53 AM Paul Sokolovsky wrote: > > Hello, > > On Wed, 2 Dec 2020 02:39:38 +1100 > Chris Angelico wrote: > > > On Wed, Dec 2, 2020 at 2:29 AM Paul Sokolovsky > > wrote: > > > def fun(): > > > # Imports are not allowed a

[Python-ideas] Re: [RFC] "Strict execution mode" (TL;DR version)

2020-12-01 Thread Chris Angelico
On Wed, Dec 2, 2020 at 2:29 AM Paul Sokolovsky wrote: > def fun(): > # Imports are not allowed at run-time > import mod2 > # But you can re-import module previously imported at import-time. > import mod Wait, what? No. No no no. Please do not do ANYTHING like this. Having suffered

[Python-ideas] Re: Making the for statement work better with nested functions

2020-11-30 Thread Chris Angelico
On Tue, Dec 1, 2020 at 10:25 AM Marco Sulla wrote: > > On Mon, 30 Nov 2020 at 23:26, David Mertz wrote: > > Somehow "dire" doesn't strike me as the right word Maybe you were > > looking for "conceivably useful in niche cases."? > > Well, I think const can be useful for: > * multiprocessing.

[Python-ideas] Re: adding a timeit.Timer context manager and decorator to time code/functions

2020-11-29 Thread Chris Angelico
On Mon, Nov 30, 2020 at 10:14 AM Marco Sulla wrote: > > On Sun, 29 Nov 2020 at 21:45, wrote: > > To use timeit (or the current Timer class), one has to write the stmt as a > > string which is not convenient (yet I understand that if you want to time a > > code snippet by running it more than on

[Python-ideas] Re: Making the for statement work better with nested functions

2020-11-26 Thread Chris Angelico
On Fri, Nov 27, 2020 at 4:34 PM Greg Ewing wrote: > > On 27/11/20 1:23 pm, Chris Angelico wrote: > >> > >> That makes no sense as a phrase in English. > > > > Nor do lots of other constructs when they get combined. English > > doesn't really

[Python-ideas] Re: Move semantics

2020-11-26 Thread Chris Angelico
On Fri, Nov 27, 2020 at 2:46 PM MRAB wrote: > > On 2020-11-27 02:30, Ned Batchelder wrote: > > On 11/26/20 9:02 PM, MRAB wrote: > >> On 2020-11-27 01:12, Ned Batchelder wrote: > >>> On 11/26/20 6:44 AM, 3mi...@gmail.com wrote: > Add something like Move type hint to typing module. It will tell

[Python-ideas] Re: Making the for statement work better with nested functions

2020-11-26 Thread Chris Angelico
On Fri, Nov 27, 2020 at 11:08 AM Greg Ewing wrote: > > I'd suggest that it should be "for let" > > That makes no sense as a phrase in English. > Nor do lots of other constructs when they get combined. English doesn't really have good parallels for most computing concepts. How will this "new assi

[Python-ideas] Re: Making the for statement work better with nested functions

2020-11-26 Thread Chris Angelico
On Fri, Nov 27, 2020 at 12:28 AM Steven D'Aprano wrote: > Block scoping adds semantic and implementation complexity and annoyance, > while giving very little benefit. No thank you. > > > > def foo(): > > let x = 1 > > if bar: > > let x = 2 > > ... > > # x is 1 again her

[Python-ideas] Re: Adding PyInstaller to the standard library

2020-11-24 Thread Chris Angelico
On Wed, Nov 25, 2020 at 12:03 PM Brendan Barnwell wrote: > > On 2020-11-24 16:47, Chris Angelico wrote: > > On Wed, Nov 25, 2020 at 10:29 AM Brendan Barnwell > > wrote: > >> > >> On 2020-11-24 00:05, Chris Angelico wrote: > >> >> > > &g

[Python-ideas] Re: Adding PyInstaller to the standard library

2020-11-24 Thread Chris Angelico
On Wed, Nov 25, 2020 at 10:29 AM Brendan Barnwell wrote: > > On 2020-11-24 00:05, Chris Angelico wrote: > >> > > >> >I'm still confused what the point is of a zipapp, if it can't be a proper > >> >point and click GUI thing, and it can'

[Python-ideas] Re: Adding PyInstaller to the standard library

2020-11-24 Thread Chris Angelico
On Wed, Nov 25, 2020 at 10:13 AM Greg Ewing wrote: > > On 24/11/20 9:05 pm, Chris Angelico wrote: > > It CAN be a proper point-and-click GUI thing. You can have a fully > > executable Python script if it has no dependencies (just distribute a > > single .py file w

[Python-ideas] Re: Adding PyInstaller to the standard library

2020-11-24 Thread Chris Angelico
On Tue, Nov 24, 2020 at 6:47 PM Christopher Barker wrote: > > On Mon, Nov 23, 2020 at 12:09 AM Paul Moore wrote: >> >> On Mon, 23 Nov 2020 at 03:37, Christopher Barker wrote: >> > My feeling is that it hits middle ground that isn't very useful. If you >> > can count on your users having a prope

[Python-ideas] Re: 'Infinity' constant in Python

2020-11-23 Thread Chris Angelico
On Tue, Nov 24, 2020 at 9:32 AM Steven D'Aprano wrote: > > On Tue, Nov 24, 2020 at 08:32:21AM +1100, Chris Angelico wrote: > > On Tue, Nov 24, 2020 at 8:26 AM Wes Turner wrote: > > > > > > Is there a different IEEE spec or CAS that distinguishes b

[Python-ideas] Re: 'Infinity' constant in Python

2020-11-23 Thread Chris Angelico
On Tue, Nov 24, 2020 at 9:05 AM Steven D'Aprano wrote: > > On Mon, Nov 23, 2020 at 04:26:20PM -0500, Wes Turner wrote: > > > Is there a different IEEE spec or CAS that distinguishes between 1/x and > > 2/x where x=0? > > No. x/0.0 would either signal an error (in Python terms: raise an > exception

<    6   7   8   9   10   11   12   13   14   15   >