Skip to content

Commit cc5e2cf

Browse files
committed
[INIT] Adding initial post for defining module level __dir__ and
__attr__
1 parent 5672cb5 commit cc5e2cf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
layout: post
3+
title: "Beautiful modules using __dir__ and __attr__"
4+
date: "2018-08-15 16:51:41 +0530"
5+
tag:
6+
- Python
7+
- Python3.7
8+
- DunderMethods
9+
---
10+
11+
* Module level definition of dunder methods __dir__() and __attr__():
12+
13+
I was facing this issue of hinding actual imports of my module with user. It
14+
was always confusing when someone calls "dir()" on my modules. There is
15+
already dunder method called "__dir__()" to override this behaviour, but this
16+
method was limited to Classes. With this version, it is possible to override
17+
the behaviour of module by defining module level ```__dir__()``` method.
18+
# TODO: Write the example of them here.
19+
* __attr__ : You can override this method for various purposes like firing an
20+
API deprication warning. The method will behave just as it was behaving on
21+
Class.
22+
# TODO: Example of __attr__ at module level.
23+
24+

0 commit comments

Comments
 (0)