From dff024e5e4d202a2937d768fcd5449fb77372b93 Mon Sep 17 00:00:00 2001 From: "Vgr E. Barry" Date: Fri, 9 Dec 2016 10:56:34 -0500 Subject: [PATCH] Allow contexts to be used directly in str.format() calls --- src/context.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/context.py b/src/context.py index 47c51b2..04bfd1e 100644 --- a/src/context.py +++ b/src/context.py @@ -113,6 +113,11 @@ class IRCContext: self.client = client self.ref = None + def __format__(self, format_spec=""): + if not format_spec: + return self.name + raise ValueError("Format specificer {0} has undefined semantics".format(format_spec)) + def lower(self): temp = type(self)(lower(name), client) temp.ref = self.ref or self