| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cd3ffe6 commit 0289b15
15 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -583,10 +583,18 @@ Once an iterator's :meth:`__next__` method raises :exc:`StopIteration`, it must | |||
| 583 | 583 | continue to do so on subsequent calls. Implementations that do not obey this | |
| 584 | 584 | property are deemed broken. | |
| 585 | 585 | ||
| 586 | + | ||
| 587 | + .. _generator-types: | ||
| 588 | + | ||
| 589 | + Generator Types | ||
| 590 | + --------------- | ||
| 591 | + | ||
| 586 | 592 | Python's :term:`generator`\s provide a convenient way to implement the iterator | |
| 587 | 593 | protocol. If a container object's :meth:`__iter__` method is implemented as a | |
| 588 | 594 | generator, it will automatically return an iterator object (technically, a | |
| 589 | 595 | generator object) supplying the :meth:`__iter__` and :meth:`__next__` methods. | |
| 596 | + More information about generators can be found in :ref:`the documentation for | ||
| 597 | + the yield expression <yieldexpr>`. | ||
| 590 | 598 | ||
| 591 | 599 | ||
| 592 | 600 | .. _typesseq: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -144,6 +144,10 @@ Examining Symbol Tables | |||
| 144 | 144 | ||
| 145 | 145 | Return ``True`` if the symbol is global. | |
| 146 | 146 | ||
| 147 | + .. method:: is_declared_global() | ||
| 148 | + | ||
| 149 | + Return ``True`` if the symbol is declared global with a global statement. | ||
| 150 | + | ||
| 147 | 151 | .. method:: is_local() | |
| 148 | 152 | ||
| 149 | 153 | Return ``True`` if the symbol is local to its block. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,8 +24,9 @@ The module defines the following public class: | |||
| 24 | 24 | ||
| 25 | 25 | The constructor takes a statement to be timed, an additional statement used for | |
| 26 | 26 | setup, and a timer function. Both statements default to ``'pass'``; the timer | |
| 27 | - function is platform-dependent (see the module doc string). The statements may | ||
| 28 | - contain newlines, as long as they don't contain multi-line string literals. | ||
| 27 | + function is platform-dependent (see the module doc string). *stmt* and *setup* | ||
| 28 | + may also contain multiple statements separated by ``;`` or newlines, as long as | ||
| 29 | + they don't contain multi-line string literals. | ||
| 29 | 30 | ||
| 30 | 31 | To measure the execution time of the first statement, use the :meth:`timeit` | |
| 31 | 32 | method. The :meth:`repeat` method is a convenience to call :meth:`timeit` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,13 +14,9 @@ | |||
| 14 | 14 | class MIMENonMultipart(MIMEBase): | |
| 15 | 15 | """Base class for MIME multipart/* type messages.""" | |
| 16 | 16 | ||
| 17 | - __pychecker__ = 'unusednames=payload' | ||
| 18 | - | ||
| 19 | 17 | def attach(self, payload): | |
| 20 | 18 | # The public API prohibits attaching multiple subparts to MIMEBase | |
| 21 | 19 | # derived subtypes since none of them are, by definition, of content | |
| 22 | 20 | # type multipart/* | |
| 23 | 21 | raise errors.MultipartConversionError( | |
| 24 | 22 | 'Cannot attach additional subparts to non-multipart/*') | |
| 25 | - | ||
| 26 | - del __pychecker__ | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,6 +54,7 @@ class or function within a module or module in a package. If the | |||
| 54 | 54 | ||
| 55 | 55 | import sys, imp, os, re, inspect, builtins, pkgutil | |
| 56 | 56 | from reprlib import Repr | |
| 57 | + from traceback import extract_tb as _extract_tb | ||
| 57 | 58 | try: | |
| 58 | 59 | from collections import deque | |
| 59 | 60 | except ImportError: | |
@@ -292,9 +293,9 @@ def safeimport(path, forceload=0, cache={}): | |||
| 292 | 293 | elif exc is SyntaxError: | |
| 293 | 294 | # A SyntaxError occurred before we could execute the module. | |
| 294 | 295 | raise ErrorDuringImport(value.filename, info) | |
| 295 | - elif exc is ImportError and \ | ||
| 296 | - str(value).lower().split()[:2] == ['no', 'module']: | ||
| 297 | - # The module was not found. | ||
| 296 | + elif exc is ImportError and _extract_tb(tb)[-1][2]=='safeimport': | ||
| 297 | + # The import error occurred directly in this function, | ||
| 298 | + # which means there is no such module in the path. | ||
| 298 | 299 | return None | |
| 299 | 300 | else: | |
| 300 | 301 | # Some other error occurred during the importing process. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,18 @@ def test_file_parse(self): | |||
| 49 | 49 | unlink(TESTFN+".pyc") | |
| 50 | 50 | sys.path.pop(0) | |
| 51 | 51 | ||
| 52 | + def test_error_from_string(self): | ||
| 53 | + # See http://bugs.python.org/issue6289 | ||
| 54 | + input = "# coding: ascii\n\N{SNOWMAN}".encode('utf-8') | ||
| 55 | + try: | ||
| 56 | + compile(input, "<string>", "exec") | ||
| 57 | + except SyntaxError as e: | ||
| 58 | + expected = "'ascii' codec can't decode byte 0xe2 in position 16: " \ | ||
| 59 | + "ordinal not in range(128)" | ||
| 60 | + self.assertTrue(str(e).startswith(expected)) | ||
| 61 | + else: | ||
| 62 | + self.fail("didn't raise") | ||
| 63 | + | ||
| 52 | 64 | def test_main(): | |
| 53 | 65 | test.support.run_unittest(CodingTest) | |
| 54 | 66 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -243,6 +243,24 @@ | |||
| 243 | 243 | ... | |
| 244 | 244 | TypeError: id() takes no keyword arguments | |
| 245 | 245 | ||
| 246 | + A corner case of keyword dictionary items being deleted during | ||
| 247 | + the function call setup. See <http://bugs.python.org/issue2016>. | ||
| 248 | + | ||
| 249 | + >>> class Name(str): | ||
| 250 | + ... def __eq__(self, other): | ||
| 251 | + ... try: | ||
| 252 | + ... del x[self] | ||
| 253 | + ... except KeyError: | ||
| 254 | + ... pass | ||
| 255 | + ... return str.__eq__(self, other) | ||
| 256 | + ... def __hash__(self): | ||
| 257 | + ... return str.__hash__(self) | ||
| 258 | + | ||
| 259 | + >>> x = {Name("a"):1, Name("b"):2} | ||
| 260 | + >>> def f(a, b): | ||
| 261 | + ... print(a,b) | ||
| 262 | + >>> f(**x) | ||
| 263 | + 1 2 | ||
| 246 | 264 | """ | |
| 247 | 265 | ||
| 248 | 266 | from test import support | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,15 @@ | |||
| 1 | 1 | import sys | |
| 2 | 2 | import os | |
| 3 | + import os.path | ||
| 3 | 4 | import difflib | |
| 4 | 5 | import subprocess | |
| 5 | 6 | import re | |
| 6 | 7 | import pydoc | |
| 7 | 8 | import inspect | |
| 8 | 9 | import unittest | |
| 9 | 10 | import test.support | |
| 11 | + from contextlib import contextmanager | ||
| 12 | + from test.support import TESTFN, forget, rmtree, EnvironmentVarGuard | ||
| 10 | 13 | ||
| 11 | 14 | from test import pydoc_mod | |
| 12 | 15 | ||
@@ -183,6 +186,9 @@ class B(builtins.object) | |||
| 183 | 186 | # output pattern for missing module | |
| 184 | 187 | missing_pattern = "no Python documentation found for '%s'" | |
| 185 | 188 | ||
| 189 | + # output pattern for module with bad imports | ||
| 190 | + badimport_pattern = "problem in %s - ImportError: No module named %s" | ||
| 191 | + | ||
| 186 | 192 | def run_pydoc(module_name, *args): | |
| 187 | 193 | """ | |
| 188 | 194 | Runs pydoc on the specified module. Returns the stripped | |
@@ -254,6 +260,42 @@ def test_not_here(self): | |||
| 254 | 260 | self.assertEqual(expected, result, | |
| 255 | 261 | "documentation for missing module found") | |
| 256 | 262 | ||
| 263 | + def test_badimport(self): | ||
| 264 | + # This tests the fix for issue 5230, where if pydoc found the module | ||
| 265 | + # but the module had an internal import error pydoc would report no doc | ||
| 266 | + # found. | ||
| 267 | + modname = 'testmod_xyzzy' | ||
| 268 | + testpairs = ( | ||
| 269 | + ('i_am_not_here', 'i_am_not_here'), | ||
| 270 | + ('test.i_am_not_here_either', 'i_am_not_here_either'), | ||
| 271 | + ('test.i_am_not_here.neither_am_i', 'i_am_not_here.neither_am_i'), | ||
| 272 | + ('i_am_not_here.{}'.format(modname), 'i_am_not_here.{}'.format(modname)), | ||
| 273 | + ('test.{}'.format(modname), modname), | ||
| 274 | + ) | ||
| 275 | + | ||
| 276 | + @contextmanager | ||
| 277 | + def newdirinpath(dir): | ||
| 278 | + os.mkdir(dir) | ||
| 279 | + sys.path.insert(0, dir) | ||
| 280 | + yield | ||
| 281 | + sys.path.pop(0) | ||
| 282 | + rmtree(dir) | ||
| 283 | + | ||
| 284 | + with newdirinpath(TESTFN), EnvironmentVarGuard() as env: | ||
| 285 | + env['PYTHONPATH'] = TESTFN | ||
| 286 | + fullmodname = os.path.join(TESTFN, modname) | ||
| 287 | + sourcefn = fullmodname + os.extsep + "py" | ||
| 288 | + for importstring, expectedinmsg in testpairs: | ||
| 289 | + f = open(sourcefn, 'w') | ||
| 290 | + f.write("import {}\n".format(importstring)) | ||
| 291 | + f.close() | ||
| 292 | + try: | ||
| 293 | + result = run_pydoc(modname).decode("ascii") | ||
| 294 | + finally: | ||
| 295 | + forget(modname) | ||
| 296 | + expected = badimport_pattern % (modname, expectedinmsg) | ||
| 297 | + self.assertEqual(expected, result) | ||
| 298 | + | ||
| 257 | 299 | def test_input_strip(self): | |
| 258 | 300 | missing_module = " test.i_am_not_here " | |
| 259 | 301 | result = str(run_pydoc(missing_module), 'ascii') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -407,8 +407,8 @@ def create_parser(*args, **kwargs): | |||
| 407 | 407 | # --- | |
| 408 | 408 | ||
| 409 | 409 | if __name__ == "__main__": | |
| 410 | - import xml.sax | ||
| 410 | + import xml.sax.saxutils | ||
| 411 | 411 | p = create_parser() | |
| 412 | - p.setContentHandler(xml.sax.XMLGenerator()) | ||
| 412 | + p.setContentHandler(xml.sax.saxutils.XMLGenerator()) | ||
| 413 | 413 | p.setErrorHandler(xml.sax.ErrorHandler()) | |
| 414 | - p.parse("../../../hamlet.xml") | ||
| 414 | + p.parse("http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml") | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -482,6 +482,7 @@ Andrew McNamara | |||
| 482 | 482 | Craig McPheeters | |
| 483 | 483 | Lambert Meertens | |
| 484 | 484 | Bill van Melle | |
| 485 | + Lucas Prado Melo | ||
| 485 | 486 | Luke Mewburn | |
| 486 | 487 | Mike Meyer | |
| 487 | 488 | Steven Miale | |
| Back | FazBrowse Home | New Git URL |
0 commit comments