ANN: repology-client library to access Repology API

2024-01-10 Thread Anna (cybertailor) Vyalkova via Python-list
Hi newsgroup,

I needed to fetch Repology data for my pet project and now it's a
library:
https://pypi.org/project/repology-client/

It uses aiohttp, if that matters.

Feel free to use and contribute.

-- 
https://mail.python.org/mailman/listinfo/python-list


extend behaviour of assignment operator

2024-01-10 Thread Guenther Sohler via Python-list
Hi,

when i run this code

a = cube([10,1,1])
b = a

i'd like to extend the behaviour  of the assignment operator
a shall not only contain the cube, but  the cube shall also know which
variable name it
was assigned to, lately. I'd like to use that for improved user interaction.

effective code should be:

a=cube([10,1,1])
a.name='a'

b=a
b.name='b' # i am aware that a.name also changes


can decorators also be used with assignment operators ?

thank you for your hints
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extend behaviour of assignment operator

2024-01-10 Thread Dieter Maurer via Python-list
Guenther Sohler wrote at 2024-1-9 08:14 +0100:
>when i run this code
>
>a = cube([10,1,1])
>b = a
>
>i'd like to extend the behaviour  of the assignment operator
>a shall not only contain the cube, but  the cube shall also know which
>variable name it
>was assigned to, lately. I'd like to use that for improved user interaction.

`Acquisition` (--> `PyPI`) implements something similar.

It does not work for variables -- but for attribute access.
Look at the following code:

```
from Acquisition import Implicit

class AccessAwareContainer(Implicit):
  ...

class AccessAwareContent(Implicit):
 ...

container = AccessAwareContainer()
container.content = AccessAwareContent()
```

When you now assign `content = container.content`, then
`content` knows that it has been accessed via `container`.


If fact `content` is not a true `AccessAwareContent` instance
but a wrapper proxy for it. It mostly behaves like an
`AccessAwareContent` object but has additional information
(e.g. it knows the access parent).


It works via a special `__getattribute__` method, essentially
implemented by:

```
   def __getattribute__(self, k):
 v = super().__getattribute__(k)
 return v.__of__(self) if hasattr(v, "__of__") else v
```

Your use case could be implemented similarly (again not for variables
and all objects, but for special classes (and maybe special objects)).

Your `__getattribute__` could look like:
```
   def __getattribute__(self, k):
 v = super().__getattribute__(k)
 try:
   v.name = k
 except TypeError: pass
 return v
```
-- 
https://mail.python.org/mailman/listinfo/python-list