From 72bc346a6da3e310ff6fc5c281f357df8635ae3b Mon Sep 17 00:00:00 2001 From: decorator-factory <42166884+decorator-factory@users.noreply.github.com> Date: Wed, 13 Nov 2019 23:40:35 +0300 Subject: [PATCH] Fix indentation in classmethod.md --- tags/classmethod.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tags/classmethod.md b/tags/classmethod.md index 424dd05..a4e8030 100644 --- a/tags/classmethod.md +++ b/tags/classmethod.md @@ -3,13 +3,13 @@ Although most methods are tied to an _object instance_, it can sometimes be usef For example, you may be writing a class that takes some magic token (like an API key) as a constructor argument, but you sometimes read this token from a configuration file. You could make use of a `@classmethod` to create an alternate constructor for when you want to read from the configuration file. ```py class Bot: -def __init__(self, token: str): -self._token = token + def __init__(self, token: str): + self._token = token -@classmethod -def from_config(cls, config: dict) -> Bot: -token = config['token'] -return cls(token) + @classmethod + def from_config(cls, config: dict) -> Bot: + token = config['token'] + return cls(token) # now we can create the bot instance like this alternative_bot = Bot.from_config(default_config)