Request: inspect: signature & getfullargspec & getcallargs

2023-12-03 Thread Dom Grigonis via Python-list
Hello, I have a request. Would it be possible to include `follow_wrapper_chains` and `skip_bound_arg` arguments to higher level functions of `inspect` module? Would exposing them, but setting defaults to what they currently are, be possible? I sometimes need: * `getcallargs`, but with

Re: on writing a number as 2^s * q, where q is odd

2023-11-29 Thread Dom Grigonis via Python-list
def powers_of_2_in(n): s = 0 while n % 2 == 0: s += 1 n = n // 2 return s, n > On 30 Nov 2023, at 02:44, Julieta Shem via Python-list > wrote: > > How would you write this procedure? > > --8<---cut here---start->8--- > def powers_

Re: argparse argument post-processing

2023-11-27 Thread Dom Grigonis via Python-list
Yeah, I have been hearing that people are having troubles converting, but I have only used argparse - got lucky there I guess. I am thinking just making the function which spits the class out. Maybe not very optimised solution, but simple. Argument parsing in my case is very far from being a bo

Re: argparse argument post-processing

2023-11-27 Thread Dom Grigonis via Python-list
ats Wichmann via Python-list > wrote: > > On 11/27/23 04:29, Dom Grigonis via Python-list wrote: >> Hi all, >> I have a situation, maybe someone can give some insight. >> Say I want to have input which is comma separated array (e.g. >> paths='path1,path2,pat

argparse argument post-processing

2023-11-27 Thread Dom Grigonis via Python-list
Hi all, I have a situation, maybe someone can give some insight. Say I want to have input which is comma separated array (e.g. paths='path1,path2,path3') and convert it to the desired output - list: import argparse parser = argparse.ArgumentParser() parser.add_argument('paths', type=lambda x: li

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dom Grigonis via Python-list
Thank you. > On 16 Nov 2023, at 21:30, Dieter Maurer wrote: > > Dom Grigonis wrote at 2023-11-16 21:11 +0200: >> ... >>> On 16 Nov 2023, at 21:00, Dieter Maurer wrote: >>> ... >>> Methods are not bound during instance creation, they are bound during >>> access. >> >> Good to know. What is the

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dom Grigonis via Python-list
> On 16 Nov 2023, at 21:00, Dieter Maurer wrote: > > Dom Grigonis wrote at 2023-11-16 20:12 +0200: >> What I am interested in is a callback. >> Preferably just after methods get bound. So in `object.__new__`. > >> I have done it via metaclass, but it is not ideal as there would be too much >

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dom Grigonis via Python-list
What I am interested in is a callback. Preferably just after methods get bound. So in `object.__new__`. I have done it via metaclass, but it is not ideal as there would be too much overhead. I think what I am looking for is custom method binding. Regards, DG > On 16 Nov 2023, at 20:02, Dieter

Re: xor operator

2023-11-15 Thread Dom Grigonis via Python-list
In case someone is actually going to execute the code, there is a bug: `set` need to be wrapped in `len` for criteria args. > On 15 Nov 2023, at 20:13, Dom Grigonis wrote: > > > The specific situation was related to truth values and following out of that > my considerations regarding equivale

__set_name__ equivalent for instance

2023-11-15 Thread Dom Grigonis via Python-list
So there is a method __set_name__ which is called on class creation. The functionality that I am interested in is not retrieving name, but the fact that it also receives `owner` argument. Thus, allowing simulation of bound class method. I was wandering if there is an equivalent functionality of

Re: xor operator

2023-11-15 Thread Dom Grigonis via Python-list
The specific situation was related to truth values and following out of that my considerations regarding equivalent of all and any for counting `truths`. So one of the specific examples: class Publisher: def __init__(self): self.subscribers = dict() def subscribe(self, sub, crit

Re: xor operator

2023-11-15 Thread Dom Grigonis via Python-list
significantly slower. Regards, DG > On 15 Nov 2023, at 02:34, Peter J. Holzer via Python-list > wrote: > > On 2023-11-14 00:11:30 +0200, Dom Grigonis via Python-list wrote: >> Benchmarks: >> test1 = [False] * 100 + [True] * 2 >> test2 = [True] * 100 + [False] * 2 >

Re: xor operator (DEPRECATED)

2023-11-13 Thread Dom Grigonis via Python-list
t >>> would have to be the first n items without a failure. >>> >>> Fine, but then someone may want to know WHERE you stopped or for you to >>> return the sublist of the ones that made the match, or even return >>> everything that was skipped so you can l

Re: xor operator (DEPRECATED)

2023-11-13 Thread Dom Grigonis via Python-list
- > From: Python-list On > Behalf Of Grant Edwards via Python-list > Sent: Monday, November 13, 2023 8:19 PM > To: python-list@python.org > Subject: Re: xor operator > > On 2023-11-14, Dom Grigonis via Python-list wrote: >> >>> Except the 'any'

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
thing. DG > On 14 Nov 2023, at 02:33, Mats Wichmann via Python-list > wrote: > > On 11/13/23 16:24, Dom Grigonis via Python-list wrote: >> I am not arguing that it is a generalised xor. >> I don’t want anything, I am just gauging if it is specialised or if there is >

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
> Except the 'any' and 'all' builtins are _exactly_ the same as bitwise > or and and applided to many bits. To do something "in line" with that > using the 'xor' operator would return True for an odd number of True > values and False for an even Number of True values. Fair point. Have you ever

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
some time to even convey what I mean. Bad naming didn’t help ofc, but if it was something that is needed I think it would have clicked much faster. Thanks, DG > On 14 Nov 2023, at 01:12, Chris Angelico via Python-list > wrote: > > On Tue, 14 Nov 2023 at 10:00, Dom Grigonis via

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
applied to many bits. This is more in line with cases that `any` and `all` builtins are used. > On 14 Nov 2023, at 00:51, Grant Edwards via Python-list > wrote: > > On 2023-11-13, Dom Grigonis via Python-list wrote: >> Hi All, >> >> I think it could be useful to

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
Benchmarks: test1 = [False] * 100 + [True] * 2 test2 = [True] * 100 + [False] * 2 TIMER.repeat([ lambda: xor(test1), # 0.0168 lambda: xor(test2), # 0.0172 lambda: xor_ss(test1), # 0.1392 lambda: xor_ss(test2), # 0.0084 lambda: xor_new(test1), # 0.0116 lambda: xor_

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
xor([True, False, False, False], n=1) xor([False, False, False, True], n=1) Both of the above would evaluate to true. Well, it depends how you interpret it. In binary case it reads: “exclusively one positive bit or the other, but not both” In this case one could read: “exclusively one positive se

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
. Regards, DG > On 13 Nov 2023, at 19:42, Barry wrote: > > > >> On 13 Nov 2023, at 15:16, Dom Grigonis via Python-list >> wrote: >> >> I think it could be useful to have `xor` builtin, which has API similar to >> the one of `any` and `all`. >

xor operator

2023-11-13 Thread Dom Grigonis via Python-list
Hi All, I think it could be useful to have `xor` builtin, which has API similar to the one of `any` and `all`. * Also, it could have optional second argument `n=1`, which indicates how many positives indicates `True` return. * For complete flexibility 3rd argument could indicate if `the number`

Re: Question(s)

2023-10-24 Thread Dom Grigonis via Python-list
I don’t think there i a simple answer to this, although if you find something interesting, please share. From my experience, industry is applying variety of testing methods. Starting from lowest level components and implementing unit tests, finishing with end-to-end testing platforms. https://

Re: Using generator expressions

2023-09-25 Thread Dom Grigonis via Python-list
y = test1(*[a for a in st]) y = test1(*st) Maybe any of these would be ok for you? Regards, DG > On 25 Sep 2023, at 17:15, Jonathan Gossage via Python-list > wrote: > > I am having a problem using generator expressions to supply the arguments > for a class instance initialization. The followi

Re: iterations destroy reversed() results

2023-09-03 Thread Dom Grigonis via Python-list
It is by design. `sorted` returns a list, while `reversed` returns an iterator. Iterators are exhaust-able, and not reusable. So be mindful of this and if you are going to "re-use” the sequence returned by iterator, convert it to list first. Have a look at `itertools` library, which contains a

Re: Fallback for operator and other dunder methods

2023-08-04 Thread Dom Grigonis via Python-list
The issue was more of a wrapping around numpy array. Found the solution already. Unfortunately, there is no equivalent to __getattr__, the only way is to dynamically define them from meta. It seems it’s pretty standard to just have a collection of special method names and using them for similar

Re: Fallback for operator and other dunder methods

2023-07-26 Thread Dom Grigonis via Python-list
Tried exactly that and didn’t work. Neither __getattr__, nor __getattribute__ of meta is being invoked. > On 26 Jul 2023, at 10:01, Chris Angelico via Python-list > wrote: > > On Wed, 26 Jul 2023 at 16:52, Dom Grigonis wrote: >> >> Could you give an example? Something isn’t working for me. >

Re: Fallback for operator and other dunder methods

2023-07-25 Thread Dom Grigonis via Python-list
Could you give an example? Something isn’t working for me. > On 26 Jul 2023, at 09:40, Chris Angelico via Python-list > wrote: > > On Wed, 26 Jul 2023 at 12:23, Dom Grigonis via Python-list > wrote: >> print(a + 1)# TypeError: unsupported operand type(s) fo

Fallback for operator and other dunder methods

2023-07-25 Thread Dom Grigonis via Python-list
To illustrate what I was trying to achieve: class A: def __init__(self, arr): self.arr = arr def __getattr__(self, name): arr_method = getattr(self.arr, name) def wrapper(*args, **kwargs): new_arr = arr_method(*args, **kwargs) return type(se

Re: Meta Class Maybe?

2023-07-24 Thread Dom Grigonis via Python-list
> On 23 Jul 2023, at 02:12, Chris Nyland via Python-list > wrote: > > So I am stuck on a problem. I have a class which I want to use to create > another class without having to go through the boiler plate of subclassing. > Specifically because the subclass needs to have certain class attribute