For me it's really easy given your example without the end statements.
I suppose your use case is actually about much longer code, with much more
cyclomatic complexity.
I recommend you run McCabe's algorithm instead to help refactor your code.
https://pypi.org/project/mccabe/
I think setting a patch mock's side_effect to raise an exception is a valid
use case.
In this example, we're simulating a blockchain error in an API that we're
coding, and testing that instead of a 500 Internal Server Error, our API
returns a 400 with a nice error message:
with
Ok, just after I posted this I checked if side_effect would take an
exception as value and handle raising it itself and it does, which sort of
invalidates that specific use case, but at the same time we just deported
that feature into python code of mock.
TBH I had read about mutating methods returning None, and the fluent
thread, I just didn't make the relation.
Thanks Ned for the assignment operator reminder, that solves my use case
perfectly.
Have a great day
Also,
I love you <3
___
Python-ideas
Hi all,
Currently, list.append(x) mutates the list and returns None.
It would be a little syntactic sugar to return x, for example:
something = mylist.append(Something())
What do you think ?
Thanks in advance for your replies
--
∞
___
Well personally I don't need print at all, I just read code and
imagine the output in my head and that's perfectly fine for me (I
don't even need a tty).
Nonetheless, I believe the majority of Python users are not
necessarily familiar with PDB and would be using print as their main
debugging
ERRATA : s/A lot of debuggers/A lot of developers/ (sorry I think I squinted)
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
+1 because print is a debugging tool mostly used in short lived
temporary code as such the parenthesis do not matter and do not
provide any value.
A lot of debugger use print to instrumentalize their code during
development or debugging, as in: "I want to dump some variable and run
my test again"
Well correct me if I'm wrong (I did a bit of homework), but threads are
hard to get right because they may switch at any time.
When we do async instead of threads, it's because we want task switch on
blocking operations only.
The thing that is still not quite clear to me, and really I must
> This proposal would elevate it to a very special status,
making it effectively part of the language rather than just a module
in the stdlib.
Indeed, thank you Greg for the clarification
___
Python-ideas mailing list -- python-ideas@python.org
To
Good point, but then I'm not sure the decoder could be used for untrusted
json anymore.
Another solution would be to generate a schema in a separate variable,
which would represent the JSON structure with Python types.
Also, there's still simple regexp pattern matching that could also be good
> Why bother with JSON and all of its verbosity and restrictions in the
first place?
Well PostgreSQL offers query abilities on JSON fields nowadays, so that's
the reason I've been migrating stuff from pickle to json, because then I
can query on the data.
I understand, do you think the python standard library should provide a
JSONEncoder and JSONDecoder that supports python standard library objects ?
It would be optional to use, but if you use it then any object from the
python standard library will just work.
Hi all,
This is a proposal to enable uuid objects serialization / deserialization
by the json module out of the box.
UUID objects cast to string:
>>> example = uuid.uuid4()
>>> str(example)
'b8bcbfaa-d54f-4f33-9d7e-c91e38bb1b63'
The can be casted from string:
>>> example ==
Or, there might be a way to get the best of both worlds. Consider this
silly example:
encoded = yourobject.__jsondump__()
# this should work
yourobject == YourClass.__jsonload__(encoded)
Basically very similar to __getstate__ and __setstate__ with pickle, with
the following
> I don't think the stdlib needs to cater to that requirement
> when there are hooks to write your own customizations.
If the stdlib offers such hooks, as well as objects that don't serialize by
default, why not ship a usable hook that would serialize anything from the
stdlib by default ? It
I published a lib on PyPi that does that, which pushed to write a complete
readme, that I will reproduce here if anybody is interested in more
discussion about this, along with my conclusions:
Overall, it seems like the cost of maintenance is going to be
insignificant.
While the value is reduced
What if you want to import a lib in two different scripts, would you have
to call your import function with the given version (and permissions I
suppose, if you want to follow Deno's path) every time ?
IMHO, being able to set the permissions of an imported library like Deno
does could be
I find this interesting, another solution would be for locals() to take
arguments:
dict(tel='1337-1337', **locals('name', 'surname'))
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
> I do think there is some case for non rentrency and nested loop where
what you define here would block an outer loop, but most people
suggesting what you ask actually want re-entrency, which is not
possible there.
Do you mean that it's not possible to implement this at the syntax level
because
Hi all,
Currently, you can not use await outside an async function, the following
code:
async def lol():
return 'bar'
def test():
return await lol()
print(test())
Will fail with: SyntaxError: 'await' outside async function
Of course, you can use asyncio.run and then it works
Hi all,
Just wonder what it would look like if coroutines where awaited by default,
you would only have to use "noawait" when you do *not* want to await a
coroutine ?
async def test():
return do_something()
# it's awaited here by default: we get the result and not a coroutine
result1
I mean, if it pauses because of some blocking IO and switches to another
coroutine, that's just a BIG win ... I have hard times trying to figure how
that signal could be useful to me as a developer. On the other hand, I have
to (await test()).bar ...
___
Thank you for your comments,
In my experience, 99.9% of the time I don't want to do_something_else()
before I want to await do_something().
I could as well change this code:
foo.bar
To:
foo.__getattribute__('bar')
This would signal that I'm calling the __getattribute__ function.
But the
> Your project is fundamentally about instantiating processes?
Yes, that and spawning other subprocesses depending on the outcome of the
previous one, sometimes concurrently per-host but mostly sequentially, and
clearly most of the time will be spent waiting for suprocesses because all
my
I'm not sure I should rewrite my asyncio code to threading, I'll just keep
going asyncio, maybe one day it'll be possible to get the best of both
worlds ...
On #python they generally tell me that the extra syntax is worth it because
of the internal details, that rewriting to threads does not seem
My bad, I had missed nesting template literals support in the PEP, it makes
it interesting then!
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
On Thu, Jun 10, 2021 at 8:34 AM Thomas Güttler
wrote:
>
> This solution has two drawbacks:
>
>1. It is too verbose. Typing "conditional_escape(...)" again and again
>is cumbersome.
>
> from django import conditional_espace as esc
f'''
Hi {esc(name)}
Your messages: {esc(messages)}
'''
>
On Thu, Jun 10, 2021 at 4:07 PM Chris Angelico wrote:
>
> What's the advantage of htmx? When I want to build a good interactive
> web site, my general pattern is a back end with a well-defined API,
> and a front end in JavaScript that makes use of this API. That API is
> usually going to be
Oh, I didn't think of it, thank you Paul.
Inspiration from JavaScript was not a good idea. Instead, would like to
propose to make the "def" keyword optional like in bash:
foo(x): len(x)
Would be equivalent to:
foo = lambda x: len(x)
Would that work?
On Thu, Feb 11, 2021 at 12:24
Hi all,
Lambdas can be defined as such:
w = lambda: [12]
x = lambda y: len(y)
I'd like to propose the following:
w = (): [12]
x = (y): len(y)
Or even another contraction for when there are no arguments:
w =: [12]
This would also be consistent with the other proposal on anonymous
functions
changing proposal, but was wondering if it
was "nice enough" to be worth proposing.
Le jeu. 11 févr. 2021 à 15:43, Steven D'Aprano a
écrit :
> On Thu, Feb 11, 2021 at 12:42:39PM +0100, J. Pic wrote:
>
> > foo(x): len(x)
> >
> > Would be equivalent to:
> >
Hi
Currently we can upload signed packages on pypi.
Shouldn't pip have a keyring of thrusted projects or developers and enforce
whitelisting of untrusted packages, either through a requirement flag or
through an interactive question in CLI?
I think this would help with user security if we want
33 matches
Mail list logo