From cc5e2cf3d8646781d82aa78a3d794f05d63e7633 Mon Sep 17 00:00:00 2001 From: Jaysinh Shukla Date: Wed, 15 Aug 2018 16:53:50 +0530 Subject: [PATCH] [INIT] Adding initial post for defining module level __dir__ and __attr__ --- ...15-beautiful-modules-using-dir-and-attr.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 _posts/2018-08-15-beautiful-modules-using-dir-and-attr.md diff --git a/_posts/2018-08-15-beautiful-modules-using-dir-and-attr.md b/_posts/2018-08-15-beautiful-modules-using-dir-and-attr.md new file mode 100644 index 0000000..3398501 --- /dev/null +++ b/_posts/2018-08-15-beautiful-modules-using-dir-and-attr.md @@ -0,0 +1,24 @@ +--- +layout: post +title: "Beautiful modules using __dir__ and __attr__" +date: "2018-08-15 16:51:41 +0530" +tag: + - Python + - Python3.7 + - DunderMethods + --- + +* Module level definition of dunder methods __dir__() and __attr__(): + + I was facing this issue of hinding actual imports of my module with user. It + was always confusing when someone calls "dir()" on my modules. There is + already dunder method called "__dir__()" to override this behaviour, but this + method was limited to Classes. With this version, it is possible to override + the behaviour of module by defining module level ```__dir__()``` method. + # TODO: Write the example of them here. + * __attr__ : You can override this method for various purposes like firing an + API deprication warning. The method will behave just as it was behaving on + Class. + # TODO: Example of __attr__ at module level. + +