File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments