Stefan Behnel schrieb am 29.09.20 um 11:48:
> Salve Stefano,
>
> Stefano Borini schrieb am 23.09.20 um 22:55:
>> "Support for indexing with keyword arguments" has now been merged with
>> the assigned PEP number 637.
>
> Cool, this looks like a great addition to the language!
>
> One thing that I
Hi,
Please pardon me if my idea is not making sense or already exists, I'm kind
of new to developing in Python but I had this idea today and I wanted to
share it with you.
I think a class type such as "@functionclass" may be helpful for creating
functions intended to keep a list of methods in a s
On Tue, Oct 6, 2020 at 00:37 Kevin Mills wrote:
> str_iterator, bytes_iterator, range_iterator, list_iterator, and
> tuple_iterator (and probably others) should have a method that is capable
> of efficiently advancing the iterator, instead of having to call next
> repeatedly.
>
> I suggest adding
Hi Alperen,
Why do you need a class at all rather than just a module with some functions?
Irit
On Tuesday, October 6, 2020, 01:38:21 PM GMT+1, Alperen Keleş
wrote:
Hi,
Please pardon me if my idea is not making sense or already exists, I'm kind of
new to developing in Python but I had
I cannot answer for Alperen, but I commonly encounter this when writing
testing code: generally I use the format:
some_module.py
tests/test_some_module.py
where it is expected the filename to test a module is
"test_module_name.py". However, within that, I might want to namespace
based on the clas
Hi Irit,
In my case, the code structure is as below.
I'm writing a city traffic simulator which includes roads and cars.
Cars have different states, MovingCar, IdleCar, ParkingCar...
A car can move between different states and it keeps the same information.
My solution to this was,
Having a d
cf. this relatively recent conversation on the same topic-- worth reading
in entirety:
https://mail.python.org/archives/list/python-ideas@python.org/thread/TAVHEKDZVYKJUGZKWSVZVAOGBPLZVKQG/
As I said in that conversation, in the past I have wanted to have
module-like namespaces inside of modules
I think the OP would be happy with a decorator they can just copy-paste.
All it needs to do is go over the class dict and apply @classmethod to
every “normal” function. Probably skip under names.
On Tue, Oct 6, 2020 at 06:46 Ricky Teachey wrote:
> cf. this relatively recent conversation on the s
SUMMARY
This post asks for some examples that will improve PEP 637, by providing
examples where the existing language specification is not adequate (but PEP
637 is). The rest of this post should tell you why I want these examples,
and what they should look like.
DISCLAIMER
I'm an editor of PEP 637
I was just working on that, although I prefer staticmethod:
def allstatic(cls):
for key, value in cls.__dict__.items():
if not key.startswith('__'):
setattr(cls, key, staticmethod(value))
return cls
@allstatic
class C:
def foo(a, b):
print(f'{a}, {b}')
C.
On Wed, Oct 7, 2020 at 2:08 AM Jonathan Fine wrote:
> Aside. Please treat this as a semantic problem, or in other words assume that
> >>> x[SOMETHING]
> >>> f(SOMETHING)
> impose the same constraint on a well-formed expression SOMETHING.
>
Be aware that this isn't an "expression" in the t
In the meanwhile, I updated the code of frozendict to the new 3.10
code. And here I need some help.
As you can see by the new benchs:
https://github.com/Marco-Sulla/cpython/blob/frozendict/frozendict/test/bench.txt
creation of frozendict is not faster anymore. This is because Inada
introduced mem
Sorry for the duplicate message. I realized two seconds after I sent it, that I
only replied to you and not the group.
I didn't see the `consume` recipe until after I posted, or I probably would've
mentioned it. What I want would have to be done in C, because `it_index` (as
`listiterobject` and
NOTE 1:
After writing this whole post, I realized that while you used @classmethod,
what you seem to really want is a fully @staticmethod class -- certainly
your example was a static method, and some other posters were talking about
static method (i.e. "it's bad style to have unused parameters in a
What I do not understand is why you need to use the iterator instead
of using the iterable itself. This way you can jump to whatever
position without slicing.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-
I suspect you will encounter a bit of resistence here, because itertools is
about, well, itertors, and designbed to work with arbitrary iterables, and
what you are looking for is somnethign optimized for Sequences. Which
doesn't mean it couldn't be there.
> Slicing large lists/strings/bytes/tuples
On Tue, Oct 6, 2020 at 10:14 AM Marco Sulla
wrote:
> What I do not understand is why you need to use the iterator instead
> of using the iterable itself. This way you can jump to whatever
> position without slicing.
>
if you want the Nth item, that's easy, yes.
if you want to iterate through it
Currently there are a few Protocols
https://docs.python.org/3/library/typing.html#protocols defined in the
typing module. One that I recently felt like was missing was a typing
annotation for classes with a __str__() method defined. Seems like a fairly
straightforward implementation.
@runtime_chec
On Tue, Oct 6, 2020 at 7:21 PM Christopher Barker
wrote:
>
>
> On Tue, Oct 6, 2020 at 10:14 AM Marco Sulla
> wrote:
>
>> What I do not understand is why you need to use the iterator instead
>> of using the iterable itself. This way you can jump to whatever
>> position without slicing.
>>
>
> if
The nice thing about Protocols is that they are so easy to define, you can
just define them yourself. There's no need to have a "standard" protocol in
typing.py for ever single dunder method in existence.
PS. There's no need for `__slots__ = ()` assuming you're not going to
inherit directly from i
On Tue, Oct 6, 2020 at 10:28 AM Alex Hall wrote:
>
> if you want to iterate through items N to the end, then how do you do that
> without either iterating through the first N and throwing them away, or
> making a slice, which copies the rest of the sequence?
>
> ```python
> for i in range(start,
So, Sequence views that do direct addressing with doubly-linked lists?
https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence
https://docs.python.org/3/library/stdtypes.html#dict-views :
> The objects returned by dict.keys(), dict.values() and dict.items() are
view obje
Arrow Buffers, memoryview, array.array
Apache Arrow Buffers support zero-copy slicing:
> arrow::Buffer can be zero-copy sliced to permit Buffers to cheaply
reference other Buffers, while preserving memory lifetime and clean
parent-child relationships.
>
> There are many implementations of arrow::
On Tue, Oct 6, 2020 at 1:16 AM Stefan Behnel wrote:
> Stefan Behnel schrieb am 29.09.20 um 11:48:
> > One thing that I'm missing from the PEP is the C side of things, though.
> > How are C extension types going to implement this?
> >
> > Will there be two new slot methods for them? Something like
On Wed, Oct 7, 2020 at 4:53 AM Christopher Barker wrote:
>
> On Tue, Oct 6, 2020 at 10:28 AM Alex Hall wrote:
>>
>>
>> if you want to iterate through items N to the end, then how do you do that
>> without either iterating through the first N and throwing them away, or
>> making a slice, which c
On Tue, Oct 6, 2020, 1:21 PM Christopher Barker
> if you want to iterate through items N to the end, then how do you do that
> without either iterating through the first N and throwing them away, or
> making a slice, which copies the rest of the sequence?
>
it = (lst[i] for i in range(N, len(lst)
I am +0.3 on this as I don't personally have a need for this but do see the
utility.
I can think of a number of examples where an `__advance__` would be
preferable to any of the proposed solutions:
A skip list which doesn't support O(1) random access but can advance faster
than naively calling nex
This:
def advance(it, n):
try:
return it[n:]
except TypeError:
return itertools.islice(it, n, None)
has the disadvantages of:
1. Requiring a temporary copy of the data sliced (if len(it) is 1_000_000,
and n is 500_000, you're stuck between 500_000 pointless __next__ calls
On Wed, Oct 7, 2020 at 9:06 AM Josh Rosenberg
wrote:
>
> This:
>
> def advance(it, n):
> try:
> return it[n:]
> except TypeError:
> return itertools.islice(it, n, None)
>
> has the disadvantages of:
>
> 1. Requiring a temporary copy of the data sliced (if len(it) is 1_000_0
I’m still waiting for an example of a real app where this matters. --
--Guido (mobile)
___
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-ide
On Tue, Oct 06, 2020 at 02:27:54PM -0700, Caleb Donovick wrote:
> I am +0.3 on this as I don't personally have a need for this but do see the
> utility.
>
> I can think of a number of examples where an `__advance__` would be
> preferable to any of the proposed solutions:
[...]
For `__advance__` t
On Tue, Oct 06, 2020 at 09:30:06AM -0700, aleksiy123 wrote:
> Currently there are a few Protocols
> https://docs.python.org/3/library/typing.html#protocols defined in the
> typing module. One that I recently felt like was missing was a typing
> annotation for classes with a __str__() method defined
On Tue, Oct 6, 2020, at 02:50, Alperen Keleş wrote:
> Hi,
>
> Please pardon me if my idea is not making sense or already exists, I'm
> kind of new to developing in Python but I had this idea today and I
> wanted to share it with you.
>
> I think a class type such as "@functionclass" may be help
On Tue, Oct 6, 2020 at 9:35 PM Steven D'Aprano wrote:
> On Tue, Oct 06, 2020 at 09:30:06AM -0700, aleksiy123 wrote:
> > Currently there are a few Protocols
> > https://docs.python.org/3/library/typing.html#protocols defined in the
> > typing module. One that I recently felt like was missing was a
Jonathan,
It sounds like you want to propose a competing PEP that provides your
kwkey as a built-in as an alternative to PEP 637.
I encourage you to do so, although I have no interest in acting as
sponsor, and I fear that your window of opportunity to write a competing
PEP is small.
Alternati
On Tue, Oct 6, 2020 at 9:49 PM Random832 wrote:
> On Tue, Oct 6, 2020, at 02:50, Alperen Keleş wrote:
> > I think a class type such as "@functionclass" may be helpful for
> > creating functions intended to keep a list of methods in a scope.
> >
> > At the moment, I achieved this via writing "@cla
On Tue, Oct 06, 2020 at 04:04:37PM +0100, Jonathan Fine wrote:
> PEP 1, which defines the PEP process, states that any PEP that changes the
> existing language specification should clearly explain "why the existing
> language specification is inadequate to address the problem that the PEP
> solves
On Wed, Oct 7, 2020 at 1:46 PM Steven D'Aprano wrote:
> > Recall that we already have literal expressions such as
> > >>> [1, 2, 3] # List literal
> > >>> (1, 2, 3) # Tuple literal
> > >>> {1, 2, 3} # Set literal
>
> Point of terminology: these are not literals (although informally peo
On Tue, Oct 6, 2020 at 6:50 PM Ricky Teachey wrote:
> On Tue, Oct 6, 2020 at 9:35 PM Steven D'Aprano
> wrote:
>
>> On Tue, Oct 06, 2020 at 09:30:06AM -0700, aleksiy123 wrote:
>> > Currently there are a few Protocols
>> > https://docs.python.org/3/library/typing.html#protocols defined in the
>> >
On Tue, Oct 6, 2020 at 6:47 PM Random832 wrote:
> On Tue, Oct 6, 2020, at 02:50, Alperen Keleş wrote:
> > Please pardon me if my idea is not making sense or already exists, I'm
> > kind of new to developing in Python but I had this idea today and I
> > wanted to share it with you.
> >
> > I think
On Tue, Oct 6, 2020 at 6:16 PM Steven D'Aprano wrote:
> > My ladder two examples demonstrate that this could have utility outside
> of
> > sequences but for iterators in general.
>
> I'm sorry, I don't know what your ladder two examples are. Did you post
> them in another thread?
>
I think that
In Python 3 you can do this without any decorators.
The following works and produces the same output:
class AA:
def greet(A_instance):
print("Hello", A_instance.name)
class BB:
def greet(A_instance):
print("Hi", A_instance.name)
class A:
def __init__(self, state, name):
self.
On Tue, Oct 6, 2020 at 18:16 Steven D'Aprano wrote:
> For `__advance__` to be an official Python protocol, it would almost
> certainly have to be of use for *general purpose iterators*, not just
> specialised ones -- and probably not *hypothetical* iterators which may
> not even exist. Do you hav
On Tue, 6 Oct 2020 at 15:33, Alperen Keleş wrote:
> Cars have different states, MovingCar, IdleCar, ParkingCar...
Well, IMHO the solution is quite more simple:
class Car:
def __init__(self):
self.state = "parking"
def move(self):
if self.state != "moving":
ra
On 7/10/20 2:45 pm, Random832 wrote:
I think the feature should allow for the functions to directly access
each other from the namespace's scope without requiring an attribute
lookup.
That got me thinking, and I came up with this:
def submodule(f):
return type(f.__name__, (), f())
@submodul
I have no idea if this is a good idea, but Python already has modules to be
namespaces for a collection of functions and values.
And while a class decorator is *supposed* to return a class, it can, in
fact, return anything. So you can make a decorator that converts a class
definition to a module o
New improved version:
def submodule(f):
co = f.__code__
i = len(co.co_consts)
b = bytes([0x64, i, 0x83, 0x0, 0x53, 0x0])
f.__code__ = co.replace(
co_consts = co.co_consts + (locals,),
co_code = co.co_code[:-4] + b
)
return type(f.__name__, (), f())
@submodule
def Stuff():
47 matches
Mail list logo