Skip to content

[WIP] [INIT] Adding initial post for defining module level __dir__ and #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions _posts/2018-08-15-beautiful-modules-using-dir-and-attr.md
Original file line number Diff line number Diff line change
@@ -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.