Skip to content

Commit 615b0cc

Browse files
committed
Readme written
README with more details
1 parent 109a3e6 commit 615b0cc

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
11
# PrivateAttributesProject
22
Module to increase encapsulation in Python, not allowing the access to private members outside their classes
3+
4+
5+
## Installation
6+
7+
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install PrivateAttributesProject.
8+
9+
```bash
10+
pip3 install PrivateAttributesProject
11+
```
12+
13+
## Usage
14+
15+
```python
16+
@private_attributes_dec("a")
17+
class Example:
18+
def __init__(self):
19+
self.a: int = 12
20+
self.b: int = 12
21+
self.c: int = 12
22+
self.__d: int = 12
23+
self.__e: int = 12
24+
# Case 1.1: Trying to access the private attribute outside the class -> We will raise an AttributeError
25+
try:
26+
print(e._Example__d)
27+
except AttributeError:
28+
assert True
29+
print("The attribute __d (_Example__d) can't be accessed outside the class")
30+
else:
31+
assert False
32+
# Case 2.1: We try to access a public attribute that we altered to make private using the arguments in the decorator
33+
# -> We raise an AttributeError
34+
try:
35+
print(e._Example__d)
36+
except AttributeError:
37+
assert True
38+
print("The attribute __d (_Example__d) can't be accessed outside the class")
39+
else:
40+
assert False
41+
```
42+
43+
## Contributing
44+
For major changes, please open an issue first to discuss what you would like to change.
45+
46+
Please make sure to update tests as appropriate.
47+
48+
## License
49+
[MIT](https://choosealicense.com/licenses/mit/)

0 commit comments

Comments
 (0)