I am looking for some Python library similar to Java’s Lombok. I found puffadder 0.1, from 2016, but now that I tried to install it with pip, it does not work.
Links:
- https://pypi.org/project/puffadder/
- https://libraries.io/pypi/puffadder
- https://github.com/IgniparousTempest/puffadder
Shell output:
JavaScript
x
28
28
1
$ pip3 install puffadder
2
Collecting puffadder
3
Could not find a version that satisfies the requirement puffadder (from versions: )
4
No matching distribution found for puffadder
5
6
$ pip --version
7
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
8
9
$ pip3 --version
10
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
11
12
$ pip3 install puffadder==0.1
13
Collecting puffadder==0.1
14
Could not find a version that satisfies the requirement puffadder==0.1 (from versions: )
15
No matching distribution found for puffadder==0.1
16
17
$ pip install puffadder==0.1
18
Collecting puffadder==0.1
19
Could not find a version that satisfies the requirement puffadder==0.1 (from versions: )
20
No matching distribution found for puffadder==0.1
21
22
$ sudo lsb_release -a
23
No LSB modules are available.
24
Distributor ID: Ubuntu
25
Description: Ubuntu 18.04.3 LTS
26
Release: 18.04
27
Codename: bionic
28
So, is it not compatible anymore with modern versions of Python? Why is not in pip anymore, was it discontinued, or just lack of integration in pip (so, I could maybe clone it from GitHub).
Also, does someone know some supported alternative, apart from using @property?
Advertisement
Answer
Python 3.7 added dataclasses Which reminds me of the Lombok in Java. It generates _init_, _repr_ and some more.
JavaScript
1
14
14
1
from dataclasses import dataclass
2
3
@dataclass()
4
class Name:
5
first_name: str
6
last_name: str
7
8
yoni = Name("Yoni", "Alaluf")
9
yoni2 = Name("Jony", "Alaluf")
10
print(yoni) # Name(first_name='Yoni', last_name='Alaluf')
11
print(yoni2) # Name(first_name='Jony', last_name='Alaluf')
12
print(yoni == yoni2) # False
13
14