Re: [Python-Dev] Keyword-only parameters

2015-04-14 Thread Joe Jevnik
I personally find that keyword only arguments make for nicer APIS. It also makes subclassing easier because you are free to add new positional arguments later. Especially for boolean arguments, I think keyword only is a great API choice. On Tue, Apr 14, 2015 at 2:06 PM, Steven D'Aprano wrote: >

Re: [Python-Dev] who must makes FOR loop quicker

2015-08-05 Thread Joe Jevnik
The iterator is not revaluated, instead, it is constructing a single iterator, in this case a list_iterator. The list_iterator looks at the underyling list to know how to iterate so when you mutate the underlying list, the list_iterator sees that. This does not mee the expression used to generate t

Re: [Python-Dev] [Python-checkins] Daily reference leaks (d7e490db8d54): sum=61494

2015-10-21 Thread Joe Jevnik
Sorry about introducing this. Where can I subscribe to these automated emails. Also, how do I go about running this locally? On default I tried running `./python -m test -l test_capi` did not print anything about leaks. I think that using `object.__new__` as a decorator here is the same as subclass

Re: [Python-Dev] Is there a reference manual for Python bytecode?

2015-12-26 Thread Joe Jevnik
The number and meaning of the arguments are documented in the dis module: https://docs.python.org/3.6/library/dis.html On Sat, Dec 26, 2015 at 5:20 PM, Erik wrote: > Hi. > > Looking at ceval.c and peephole.c, there is - of course - lots of specific > hard-coded knowledge of the bytecode (e.g., n

Re: [Python-Dev] Is there a reference manual for Python bytecode?

2015-12-26 Thread Joe Jevnik
All arguments are 2 bytes, if there needs to be more, EXTENDED_ARG is used On Sat, Dec 26, 2015 at 5:51 PM, Erik wrote: > Hi Joe, > > On 26/12/15 22:36, Joe Jevnik wrote: > >> The number and meaning of the arguments are documented in the dis >> module: https://doc

Re: [Python-Dev] bitwise operations for bytes and bytearray

2016-01-07 Thread Joe Jevnik
You want to put the `xor` method in the `nb_xor` field of the `PyNumberMethods` structure that lives in the `tp_as_number` field of the bytes type object. Two things I noticed in a quick pass: you might want to add some type checking around the case where `a` or `b` is not a `PyByteArray` object. A

Re: [Python-Dev] Making sure dictionary adds/deletes during iteration always raise exception

2016-12-14 Thread Joe Jevnik
> Is it possible to add a key, triggering a resize of the dict, then remove one, and continue iterating through the old (deallocated) memory? You can add and remove keys between calling next which would resize the dictionary; however, it will not iterate through uninitialized memory. The dictiter

Re: [Python-Dev] Generator objects and list comprehensions?

2017-01-25 Thread Joe Jevnik
List, set, and dict comprehensions compile like: # input result = [expression for lhs in iterator_expression] # output def comprehension(iterator): out = [] for lhs in iterator: out.append(expression) return out result = comprehension(iter(iterator_expression)) When you make

Re: [Python-Dev] Unexpected bytecode difference

2018-01-19 Thread Joe Jevnik via Python-Dev
As a general rule, you should not expect the bytecode to be the same between different versions of CPython, including minor version changes. For example, the instructions for dictionary literals are different in 3.4, 3.5, and 3.6. On Fri, Jan 19, 2018 at 6:54 PM, Victor Stinner wrote: > Python b

[Python-Dev] inconsistency in annotated assigned targets

2018-01-25 Thread Joe Jevnik via Python-Dev
Currently there are many ways to introduce variables in Python; however, only a few allow annotations. I was working on a toy language and chose to base my syntax on Python's when I noticed that I could not annotate a loop iteration variable. For example: for x: int in range(5): ... This led

Re: [Python-Dev] inconsistency in annotated assigned targets

2018-01-25 Thread Joe Jevnik via Python-Dev
t; This was rejected because in ``for`` it would make it hard to spot the > actual > iterable, and in ``with`` it would confuse the CPython's LL(1) parser. > > > On Thu, Jan 25, 2018 at 3:17 PM, Jelle Zijlstra > wrote: > >> >> >> 2018-01-25 15

Re: [Python-Dev] Register-based VM [Was: Possible performance regression]

2019-02-26 Thread Joe Jevnik via Python-Dev
METH_FASTCALL passing arguments on the stack doesn't necessarily mean it will be slow. In x86 there are calling conventions that read all the arguments from the stack, but the rest of the machine is register based. Python could also look at ABI calling conventions for inspiration, like x86-64 where

Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-01 Thread Joe Jevnik via Python-Dev
Is it true that checking for refcount == 1 is enough? What if a user wrote: args = (compute_integer(), 5) # give away args to someone int.__iadd__(*args) here `args[0]` still has refcount=1 because only `args` owns this integer. On Fri, Sep 1, 2017 at 4:19 PM, Jelle Zijlstra wrote: > > > 2017-

Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-01 Thread Joe Jevnik via Python-Dev
The string concat optimization happens in the interpreter dispatch for INPLACE_ADD On Fri, Sep 1, 2017 at 9:10 PM, Greg Ewing wrote: > Chris Angelico wrote: > >> This particular example is safe, because the arguments get passed >> individually - so 'args' has one reference, plus there's one more

[Python-Dev] Re: Helpers for dynamic bytecode generation

2019-10-25 Thread Joe Jevnik via Python-Dev
I think this probably belongs on python-list instead of python-dev because python-dev is for development _of_ python, not _with_ python. To answer your question though, there are a few tools that do this: - https://github.com/vstinner/bytecode - https://github.com/ll/codetransformer I am