diff --git a/doc/sphinxext/gen_rst.py b/doc/sphinxext/gen_rst.py
index <HASH>..<HASH> 100644
--- a/doc/sphinxext/gen_rst.py
+++ b/doc/sphinxext/gen_rst.py
@@ -101,7 +101,7 @@ def extract_docstring(filename):
 
     docstring = ''
     first_par = ''
-    tokens = tokenize.generate_tokens(lines.__iter__().next)
+    tokens = tokenize.generate_tokens(iter(lines).next)
     for tok_type, tok_content, _, (erow, _), _ in tokens:
         tok_type = token.tok_name[tok_type]
         if tok_type in ('NEWLINE', 'COMMENT', 'NL', 'INDENT', 'DEDENT'):
COSMIT don't call magic methods directly

One tricky case left in doc/sphinxext/gen_rst.py.

Also, don't use relative imports in tests.