Skip to content

Commit 48557d0

Browse files
committed
style: use good docstring style
1 parent 8873116 commit 48557d0

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

cogapp/cogapp.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ class CogGeneratedError(CogError):
9191

9292
class CogUserException(CogError):
9393
"""An exception caught when running a user's cog generator.
94+
9495
The argument is the traceback message to print.
96+
9597
"""
9698

9799
pass
@@ -202,9 +204,11 @@ def outl(self, sOut="", **kw):
202204

203205
def error(self, msg="Error raised by cog generator."):
204206
"""The cog.error function.
207+
205208
Instead of raising standard python errors, cog generators can use
206209
this function. It will display the error without a scary Python
207210
traceback.
211+
208212
"""
209213
raise CogGeneratedError(msg)
210214

@@ -363,8 +367,10 @@ def isEndOutputLine(self, s):
363367
return self.options.sEndOutput in s
364368

365369
def createCogModule(self):
366-
"""Make a cog "module" object so that imported Python modules
367-
can say "import cog" and get our state.
370+
"""Make a cog "module" object.
371+
372+
Imported Python modules can use "import cog" to get our state.
373+
368374
"""
369375
self.cogmodule = types.SimpleNamespace()
370376
self.cogmodule.path = []
@@ -390,9 +396,10 @@ def openInputFile(self, fname):
390396

391397
def processFile(self, fIn, fOut, fname=None, globals=None):
392398
"""Process an input file object to an output file object.
393-
fIn and fOut can be file objects, or file names.
394-
"""
395399
400+
`fIn` and `fOut` can be file objects, or file names.
401+
402+
"""
396403
sFileIn = fname or ""
397404
sFileOut = fname or ""
398405
fInToClose = fOutToClose = None
@@ -589,7 +596,9 @@ def processFile(self, fIn, fOut, fname=None, globals=None):
589596

590597
def suffixLines(self, text):
591598
"""Add suffixes to the lines in text, if our options desire it.
592-
text is many lines, as a single string.
599+
600+
`text` is many lines, as a single string.
601+
593602
"""
594603
if self.options.sSuffix:
595604
# Find all non-blank lines, and add the suffix to the end.
@@ -598,8 +607,10 @@ def suffixLines(self, text):
598607
return text
599608

600609
def processString(self, sInput, fname=None):
601-
"""Process sInput as the text to cog.
610+
"""Process `sInput` as the text to cog.
611+
602612
Return the cogged output as a string.
613+
603614
"""
604615
fOld = io.StringIO(sInput)
605616
fNew = io.StringIO()
@@ -737,8 +748,9 @@ def processArguments(self, args):
737748

738749
def callableMain(self, argv):
739750
"""All of command-line cog, but in a callable form.
740-
This is used by main.
741-
argv is the equivalent of sys.argv.
751+
752+
This is used by main. `argv` is the equivalent of sys.argv.
753+
742754
"""
743755
argv = argv[1:]
744756

cogapp/makefiles.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def makeFiles(d, basedir="."):
9-
"""Create files from the dictionary `d`, in the directory named by `basedir`."""
9+
"""Create files from the dictionary `d` in the directory named by `basedir`."""
1010
for name, contents in d.items():
1111
child = os.path.join(basedir, name)
1212
if isinstance(contents, (bytes, str)):
@@ -22,8 +22,10 @@ def makeFiles(d, basedir="."):
2222

2323

2424
def removeFiles(d, basedir="."):
25-
"""Remove the files created by makeFiles.
25+
"""Remove the files created by `makeFiles`.
26+
2627
Directories are removed if they are empty.
28+
2729
"""
2830
for name, contents in d.items():
2931
child = os.path.join(basedir, name)

cogapp/test_cogapp.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,7 @@ def testMarkersSwitch(self):
526526

527527

528528
class FileStructureTests(TestCase):
529-
"""Test cases to check that we're properly strict about the structure
530-
of files.
531-
"""
529+
"""Test that we're properly strict about the structure of files."""
532530

533531
def isBad(self, infile, msg=None):
534532
infile = reindentBlock(infile)
@@ -704,14 +702,11 @@ def testNoErrorIfErrorNotCalled(self):
704702

705703

706704
class CogGeneratorGetCodeTests(TestCase):
707-
"""Unit tests against CogGenerator to see if its getCode() method works
708-
properly.
709-
"""
705+
"""Tests for CogGenerator.getCode()."""
710706

711707
def setUp(self):
712-
"""All tests get a generator to use, and short same-length names for
713-
the functions we're going to use.
714-
"""
708+
# All tests get a generator to use, and short same-length names for
709+
# the functions we're going to use.
715710
self.gen = CogGenerator()
716711
self.m = self.gen.parseMarker
717712
self.l = self.gen.parseLine
@@ -1514,9 +1509,12 @@ def testFileEncodingOption(self):
15141509

15151510

15161511
class TestCaseWithImports(TestCaseWithTempDir):
1517-
"""When running tests which import modules, the sys.modules list
1512+
"""Automatic resetting of sys.modules for tests that import modules.
1513+
1514+
When running tests which import modules, the sys.modules list
15181515
leaks from one test to the next. This test case class scrubs
15191516
the list after each run to keep the tests isolated from each other.
1517+
15201518
"""
15211519

15221520
def setUp(self):

cogapp/whiteutils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55

66
def whitePrefix(strings):
7-
"""Determine the whitespace prefix common to all non-blank lines
8-
in the argument list.
9-
"""
7+
"""Find the whitespace prefix common to non-blank lines in `strings`."""
108
# Remove all blank lines from the list
119
strings = [s for s in strings if s.strip() != ""]
1210

@@ -31,9 +29,12 @@ def whitePrefix(strings):
3129

3230

3331
def reindentBlock(lines, newIndent=""):
34-
"""Take a block of text as a string or list of lines.
32+
"""Re-indent a block of text.
33+
34+
Take a block of text as a string or list of lines.
3535
Remove any common whitespace indentation.
36-
Re-indent using newIndent, and return it as a single string.
36+
Re-indent using `newIndent`, and return it as a single string.
37+
3738
"""
3839
sep, nothing = "\n", ""
3940
if isinstance(lines, bytes):

0 commit comments

Comments
 (0)