The *re* module is a black swan, because most of stdlib raises exceptions
on invalid arguments or not being able to deliver.
It's impossible to change *re* now, so wrapping the calls should be the
right solution.
--
Juancarlo Añez
mailto:apal...@gmail.com
On Sun, Oct 22, 2023 at 5:19 AM
).
--
Juancarlo Añez
mailto:apal...@gmail.com
On Tue, Jun 9, 2020 at 8:09 PM Guido van Rossum wrote:
> In Python 3.10 we will no longer be burdened by the old parser (though 3rd
> party tooling needs to catch up).
>
> One thing that the PEG parser makes possible in about 20 lines of code is
s turned off only with -O, and some that never are?
> There are lots of ways `assert` could be improved, and the question is
> how? What is/are the best way(s)?
>
> --
> Finn Mason
>
> On Mon, Sep 13, 2021, 5:36 AM Juancarlo Añez wrote:
>
>> What about asserts that are not
__
>> 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
>> https://m
shortcutting to an "*if not"*.
I do really like this option.
On Sun, Sep 12, 2021 at 1:46 AM Steven D'Aprano wrote:
> On Sat, Sep 11, 2021 at 02:30:10PM -0400, Juancarlo Añez wrote:
>
> > *invariant* cond: etc
>
> A software invariant is still an assertion.
>
>
Sep 11, 2021 at 2:05 PM David Mertz, Ph.D.
wrote:
> On Sat, Sep 11, 2021 at 9:20 AM Juancarlo Añez wrote:
>
>> I'm happy about dropping the DBC theme and rebooting to make *assert* easier
>> to use so it gets used more.
>>
>
> I agree with Steven, Marc-Andé, an
Marc-Andre,
I must agree that the current state of assertions with "-O" and "-OO" is
difficult to impossible to change.
Perhaps I'm looking for an:
*invariant* cond: etc
Regards,
On Sat, Sep 11, 2021 at 11:00 AM Marc-Andre Lemburg wrote:
> On 11.09.2021 15:1
It's fair to note that complex arguments to assertions can be hacked with:
*assert* cond, (
f'{conputesomething} {and more}'
f''{some more}'
)
The exception type can't be changed, though.
On Sat, Sep 11, 2021 at 9:17 AM Juancarlo Añez wrote:
> Stephen,
>
> Assert
be true of the
> contracts in DBC, I don't know. But I would prefer not to mix the
> difficulties of the semantics of "contract" with the simplicity of
> the semantics of "assert".
>
> Steve
>
>
--
Juancarlo *Añez*
___
-09-09 22:31, Juancarlo Añez wrote:
> > Well, if the idea makes sense, then I'm certain that we'll have a very
> > long and productive discussion about the best syntax here (re: *:=*).
> >
> > ;-)
> >
> > For backwards compatibility and no surprises:
>
ition always,
> just use an if and a raise:
>
> How is this:
>
> if value < 0:
> raise ValueError("this only works with positive numbers")
>
> Any more difficult to read or write than:
>
> assert value >= 0, raise ValueError("this only works
d can become optional.
>
> —Guido
>
> On Thu, Sep 9, 2021 at 09:04 Juancarlo Añez wrote:
>
>> Steven,
>>
>> The purpose is to make it easier to make software more resilient.
>>
>> The inspiration was this article that reminded me that software *_will
>> al
that easy and syntactically pleasant?
On Thu, Sep 9, 2021 at 12:02 PM Juancarlo Añez wrote:
> Steven,
>
> The purpose is to make it easier to make software more resilient.
>
> The inspiration was this article that reminded me that software *_will
> always fail_*, and also rem
> On Tue, Sep 07, 2021 at 11:12:37AM -0400, Juancarlo Añez wrote:
> > I won't propose a syntax, but I think it would be useful if *assert*
> could
> > raise an exception different from *AssertionError*.
> >
> > This is in the context of "Design by contrast"
that verifies
its state at runtime through assertions.
An SO reference to the basic inquiry:
https://stackoverflow.com/questions/1569049/making-pythons-assert-throw-an-exception-that-i-choose
--
Juancarlo *Añez*
___
Python-ideas mailing list -- python-ideas@py
n3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/LLK3EQ3QWNDB54SEBKJ4XEV4LXP5HVJS/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
Juancarlo *Añez*
__
ight).
It's hard to write scripts in Python that have access to the modules they
intuitively should have access to, without patching (`sys.path.insert(...)`
is awful)
--
Juancarlo *Añez*
___
Python-ideas mailing list -- python-ideas@python.org
To uns
t easier all around. and "python -m" provides a much nicer
> project structure than "python" IMO and I'd like to encourage ppl to switch
> their "python" projects to "python -m" projects.
>
> On 2020-01-11 7:28 p.m., Juancarlo Añez wrote:
>
>
tion into python -m instead. why's that so
> bad? it's simply ergonomics.
>
> On 2020-01-11 6:28 p.m., Juancarlo Añez wrote:
>
> Soni,
>
> Perhaps what you're looking for is available by writing a short Python
> program with a shebang? Then PYTHONPATH would be set to t
e qux.py)
> >
> >
> ___
> 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
&
orough threading provided by Discourse.
Could we switch the email discussions to Discourse email? Has this been
considered earlier and rejected?
Cheers,
--
Juancarlo *Añez*
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an
()*?)
Cheers,
On Sat, Dec 28, 2019 at 4:03 PM Andrew Barnert wrote:
> On Dec 28, 2019, at 10:12, Juancarlo Añez wrote:
>
>
> As far as I understand it, my implementation of *findalliter()* matches
> the semantics in the *switch* statement.
>
>
> There’s nothing outs
_checks(s)
base = s
for i in range(2, 10):
s = base * i
g = re.findall('a', s)
assert len(g) == i
all_checks(s)
Cheers,
On Fri, Dec 27, 2019 at 5:37 PM Andrew Barnert wrote:
> > On Dec 27, 2019, at 09:00, Juancarlo Añez wrote:
> >
> &g
ailing 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
> https://mail.python.org/archives/list/python-ideas@python.org/message/524SWHDA3HVPDIQ6F6S3OMFGFX
r first(findall(...))
"""
return first(findalliter(pattern, string, flags=flags), default=default)
```
Fon *first()*, maybe calling it *take_one()* will clear up
misunderstandings about it's semantics.
--
Juancarlo *Añez*
___
Pytho
//python.org/psf/codeofconduct/
>
--
Juancarlo *Añez*
___
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 arc
* should be would be a great step forward.
--
Juancarlo *Añez*
___
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
articular. In that context,
*takeone()* sounds a lot like if any random result is fine.
The docs can be simpler (less special cases) if it's called *first()* by
just explaining that the result is *next(iter(it))* with provisions for
non-yielding iterators and default return values.
--
Juanca
* and there is
no *default=* should be the same.
--
Juancarlo *Añez*
___
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.pyt
s always a string, while the first element in the list returned by
*findall()* will be a tuple if several groups matched.
As others have pointed out, there is an asymmetry in the library regarding
Match-return and string/tuple-return functions, and that leads to
*findal(...)[0
a *findalliter()* using
the current *findall()* code, and implement *findall() *and *findfirst()* by
calling that.
On Thu, Dec 5, 2019 at 10:31 PM Guido van Rossum wrote:
> On Thu, Dec 5, 2019 at 6:16 PM Juancarlo Añez wrote:
>
>> It’s unfortunate that these functions aren’t better
e for *findfirst()* is weaker if *first()* is available.
Yet *findfirst()* solves the bigger problem.
--
Juancarlo *Añez*
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https:/
*findfirst()*.
--
Juancarlo *Añez*
___
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
https://mail.
int know to call getself, but type know not to?
>>>
>>> ChrisA
>>> ___
>>> Python-ideas mailing list -- python-ideas@python.org
>>> To unsubscribe send an email to python-ideas-le...@python.org
>&
On Sat, Apr 13, 2019 at 9:02 AM Chris Angelico wrote:
> Would be really nice to be able to spell this as a dict/set intersection.
>
> func(**(d & {'a', 'b', 'c'}))
>
That would be _very_ consistent with the ongoing discussions about
operators over dicts.
--
c=kwargs_dict["c"],
> )
>
func(**{k:v for k, v in d.items() if k in ('a','b','c'))
Or you can `def dict_filter(d, yes)` to the the above.
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://m
[ins] In [2]: x
Out[2]:
[[False, False],
[False, False],
[False, False],
[False, False],
[False, False]]
[ins] In [3]: x[1][1] = True
[ins] In [4]: x
Out[4]: [[False, True], [False, True], [False, True], [False, True],
[False, True]]
--
Juancarlo *Añez*
___
(n, m, o, p, init=float)
Maybe it could also be done with syntax, but I don't have any ideas in that
regard (I don't think "lol()" is overloaded).
Regards,
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.
On Sun, Mar 24, 2019 at 5:11 AM Jonathan Fine wrote:
> I'm willing to provide some useful information, if you're willing to write
> it up into a good blog post.
>
... or a PEP for rejection.
Deal!
--
Juancarlo *Añez*
___
Python-ideas mai
it wouldn't hurt to make Python more
familiar/friendly to people coming from other languages, even if it breaks
"There should be one-- and preferably only one --obvious way to do it."
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@
key:
if settings[MY_KEY] is True:
...
If True and False are singletons in the spec (and not only in the CPython
implementation), it should be prominent and well known.
Cheers,
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas
an exception in that after taking 8 spaces of indentation to
write the implementation of a method in Python, the sweet spot is more
around 100 chars.
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/lis
On Thu, Feb 21, 2019 at 11:32 PM Chris Angelico wrote:
> On Fri, Feb 22, 2019 at 2:27 PM Juancarlo Añez wrote:
> > Then, if exceptions are going to be part of a type, there should be a
> way to express the semantics of them (like in Eiffel), so
> stack.pop();stack.push(x) doesn'
rm hint me about the actual
exceptions a given call may actually raise.
Newer languages like Go and Swift shy away from exceptions because of the
tendency to:
try:
# something
except:
print('oops!)
--
Juancarlo *Añez*
___
Python-ideas mail
y time a dependency changes its
implementation.
The strategy of catching only exceptions of interest and letting others
pass produces less fragile and easier to test code.
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.pyt
specially if exceptions escape from the final
callback.
Is there a bug in exception handling in the generator logic, or is
unwinding just inherently wrong?
How could the needs tried to solved with unwinding be handled with async?
--
Juancarlo *Añez*
{'a': 1}
In [*2*]: {('a':1)}
File "", line 1
{('a':1)}
^
SyntaxError: invalid syntax
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Co
bsolute-need_ basis.
On Sat, Oct 27, 2018 at 8:33 PM Steven D'Aprano wrote:
> On Sat, Oct 27, 2018 at 07:37:32PM -0400, Juancarlo Añez wrote:
>
> > A `loop:` statement to replace `while True:` has probably been discussed
> at
> > length more than once.
> >
> >
A `loop:` statement to replace `while True:` has probably been discussed at
length more than once.
Does anyone keep links to the discussions?
TIA!
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org
p...@phdru.name
>Programmers don't die, they just GOSUB without RETURN.
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
globals(), number=REPS))
if __name__ == '__main__':
main()
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
ist += [item]
gets optimized to mylist.append(item).
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
+)-(\d+)$', identifier)
if not m:
raise ValueError('f{identifier} is not a valid identifier')
print(f'first part is {m.group(1)}')
print(f'first part is {m.group(2)}')
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
it or not, I expect that they will be seen as competing PEPs, not
> independent ones.
Finding a real-world example of something like the above synthetic example
would be in favor of the orthogonality.
--
Juancarlo *Añez*
___
Python-ideas mailing list
P
efore you do, and
> expect to have your PEP compared to it.
>
My intention would be to make the to proposals orthogonal, if possible, so
both/any can be accepted or rejected in their own timeline.
I'm certain that both can live together.
--
Juancarlo *Añez*
__
Hello @here,
Is there a guide about writing (and publishing) PEPs?
I'd like to write one on `while expre as v: ...` using the context
semantics of `with expr as v` (not `except E as e`).
Cheers,
___
Python-ideas mailing list
Python-ideas@python.org
ile", they pattern might be:
while get_something() as v:
if v == INCONVENIENT_SENTINEL:
break
do_something(v)
The discussion isn't over, so it could also be:
while (get_something() as v) != INCONVENIENT_SENTINEL:
do_something(v)
Anyway, if you want to propose an alternative to PEP 572, you ought to
> write your own competing PEP.
>
I don't take that as a challenge. It would be good to have different, maybe
somewhat competing PEPs. It's been done before.
--
Juancarlo *Añez*
way from ":=".
For example, Should this be valid?
if child_pid := os.fork():
parent(child_pid)
else:
child()
print(child_pid)
This shouldn't be:
if os.fork() as child_pid:
parent(child_pid)
else:
child()
print(child_pid) # child_pid is undefined
--
Juancarlo *Añez*
_
ments in favor of "as" are around the
patterns exemplified by the "re" module; patterns which seem correct and
useful, and that are used by other standard and 3rd-party modules.
if os.fork() as child_pid:
parent(child_pid)
else:
child()
Cheers!
--
Ju
tions like special_gcd() inline, right before
it is first used.
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
just by reading the code.
It could also be:
if special_gcd(x - x_base, n) as g:
return g
Cheers!
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http:/
ely be on the "don't use :=, unless" band of pundits
(already a filibuster). ":=" is like going back to "reduce()", which is
almost defunct thanks to.. us!
Cheers!
--
Juancarlo *Añez*
___
Python-ideas mailing list
Pytho
with" or "given". I don't remember if "when" was already
rejected.
http://www.thesaurus.com/browse/with?s=t
http://www.thesaurus.com/browse/given?s=t
http://www.thesaurus.com/browse/considering?s=t
http://www.thesaurus.com/browse/assume?s=t
http://www.thesaurus.com/browse/when?s=t
C
> > while (cmd := get_command()).token != CMD_QUIT:
> > cmd.do_something()
>
>
while get_command() as cmd:
if cmd.token == CMD_QUIT:
break
cmd.do_something()
--
Juancarlo *Añez*
___
Python-ideas mailing
ike the new syntax, or that I'am biased
towards using "as".
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
`if` and `while` accept `as` to bind an
expression to a variable that would be local to the structured statement.
Cheers,
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
>> Python-ideas mailing list
>> Python-ideas@python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
> ___
> Python-ideas mailin
___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
I thought this might be interesting input for the discussions about "data
classes" in Python:
https://kotlinlang.org/docs/reference/data-classes.html
I think that the use of "data class" as syntax is kind of cool, but what
really matters is the semantics they chose for Ko
I found this interesting:
https://stackoverflow.com/a/46996392
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
On Mon, Oct 30, 2017 at 12:29 PM, Guido van Rossum wrote:
> What's your proposed process to arrive at the list of recommended
> packages? And is it really just going to be a list of names, or is there
> going to be some documentation (about the vetting, not about the contents
>
d on this PEP...
Please don't break it? (or make it illegal)
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
ome ingenious mangling for
the (quasi-anonymous) type name.
Equivalence of types by structure is useful, and is very different from the
mess that using dicts as records can produce.
Cheers,
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@pytho
thod of the exception class.
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
licitely.
>
+1
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
r ways to make the source of the import
unambiguous) is common in programming languages.
Cheers,
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
g to have two very similar
> but subtly different relative import mechanisms.
>
> --
> Greg
>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-i
hose defers at the start of the function I just changed).
>From import this:
Explicit is better than implicit.
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Con
or pathlib.Path objects and might or might
> not work for some other types. Importantly, this has nothing to do with
> this proposal, but is in the nature of the protocol as it is defined *now*.
+1
--
Juancarlo *Añez*
___
Python-ideas mail
, and pop(index) removes
> (and returns) the object at the index.
The name asymmetry between .pop() and .append() has always bothered me.
Cheers!
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailm
def grand_total(self):
> return self.bar + self.baz
>
Really?!
I didn't know that idiom existed.
It is enough for many use cases, and I was just about to require typing and
pathlib on my 2.7-compatible projects.
--
Juancarlo *Añez*
_
(*args, **kw)
wrapper.register = dispatcher.register
update_wrapper(wrapper, method)
return wrapper
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http:
On Tue, May 2, 2017 at 8:43 PM, Steven D'Aprano <st...@pearwood.info> wrote:
> String methods should return strings.
>
>>> "A-B-C".split("-")
['A', 'B', 'C']
If chunk() worked for all iterables:
>>> " ".join("123
is typical: https://goo.gl/l54tx7
I don't know which would be the best syntax, but it would be convenient to
be able to declare something like:
class A:
var a = 'a'
And have "a" be an instance attribute.
--
Juancarlo *Añez*
___
Pytho
ctor. There are common and frequent use cases of "objects are mostly
data" that are partially solved in Python (mostly through namedtuple?).
Cheers!
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.py
e found in which classes define several attributes that
are initialized in the constructor I think that a library like
https://github.com/python-attrs/attrs does what's needed. The downside is
that code-writing tools (like IDEs) don't understand what's going on under
the hood.
--
Juancarlo *Añez*
__
ow what's going on.
--
Juancarlo *Añez*
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
89 matches
Mail list logo