Advertisement
rfmonk

pydocs_pickle_with_pylint.py

Oct 25th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.80 KB | None | 0 0
  1. import pickle
  2. from cStringIO import StringIO
  3.  
  4. src = StringIO()
  5. p = pickle.Pickler(src)
  6.  
  7. def persistent_id(obj):
  8.     if hasattr(obj, 'x'):
  9.         return 'the value %d' % obj.x
  10.     else:
  11.         return None
  12.  
  13. p.persistent_id = persistent_id
  14.  
  15. class Integer:
  16.     def __init__(self, x):
  17.         self.x = x
  18.     def __str__(self):
  19.         return 'My name is integer %d' % self.x
  20.  
  21. i = Integer(7)
  22. print i
  23. p.dump(i)
  24.  
  25. datastream = src.getvalue()
  26. print repr(datastream)
  27. dst = StringIO(datastream)
  28.  
  29. up = pickle.Unpickler(dst)
  30.  
  31. class FancyInteger(Integer):
  32.     def __str__(self):
  33.         return 'I am the integer %d' % self.x
  34.  
  35. def persistent_load(persid):
  36.     if persid.startswith('the value  '):
  37.         value = int(persid.split()[2])
  38.         return FancyInteger(value)
  39.     else:
  40.         raise pickle.UnpicklingError, 'Invalid persistent id'
  41.  
  42. up.persistent_load = persistent_load
  43.  
  44. j = up.load()
  45. print j
  46.  
  47. """
  48. $ pylint pickle_example_from_docs.py
  49. No config file found, using default configuration
  50. ************* Module pickle_example_from_docs
  51. C:  1, 0: Missing module docstring (missing-docstring)
  52. C:  4, 0: Invalid constant name "src" (invalid-name)
  53. C:  5, 0: Invalid constant name "p" (invalid-name)
  54. C:  7, 0: Missing function docstring (missing-docstring)
  55. C: 17, 8: Invalid attribute name "x" (invalid-name)
  56. C: 15, 0: Missing class docstring (missing-docstring)
  57. C: 15, 0: Old-style class defined. (old-style-class)
  58. C: 16, 4: Invalid argument name "x" (invalid-name)
  59. R: 15, 0: Too few public methods (0/2) (too-few-public-methods)
  60. C: 25, 0: Invalid constant name "datastream" (invalid-name)
  61. C: 27, 0: Invalid constant name "dst" (invalid-name)
  62. C: 29, 0: Invalid constant name "up" (invalid-name)
  63. C: 31, 0: Missing class docstring (missing-docstring)
  64. R: 31, 0: Too few public methods (0/2) (too-few-public-methods)
  65. C: 35, 0: Missing function docstring (missing-docstring)
  66. W: 40, 8: Use raise ErrorClass(args) instead of raise ErrorClass, args. (old-raise-syntax)
  67.  
  68.  
  69. Report
  70. ======
  71. 33 statements analysed.
  72.  
  73. Raw metrics
  74. -----------
  75.  
  76. +----------+-------+-------+---------+-----------+
  77. |type      |number |%      |previous |difference |
  78. +==========+=======+=======+=========+===========+
  79. |code      |34     |100.00 |NC       |NC         |
  80. +----------+-------+-------+---------+-----------+
  81. |docstring |0      |0.00   |NC       |NC         |
  82. +----------+-------+-------+---------+-----------+
  83. |comment   |0      |0.00   |NC       |NC         |
  84. +----------+-------+-------+---------+-----------+
  85. |empty     |0      |0.00   |NC       |NC         |
  86. +----------+-------+-------+---------+-----------+
  87.  
  88.  
  89.  
  90. Messages by category
  91. --------------------
  92.  
  93. +-----------+-------+---------+-----------+
  94. |type       |number |previous |difference |
  95. +===========+=======+=========+===========+
  96. |convention |13     |13       |=          |
  97. +-----------+-------+---------+-----------+
  98. |refactor   |2      |2        |=          |
  99. +-----------+-------+---------+-----------+
  100. |warning    |1      |1        |=          |
  101. +-----------+-------+---------+-----------+
  102. |error      |0      |0        |=          |
  103. +-----------+-------+---------+-----------+
  104.  
  105.  
  106.  
  107. Messages
  108. --------
  109.  
  110. +-----------------------+------------+
  111. |message id             |occurrences |
  112. +=======================+============+
  113. |invalid-name           |7           |
  114. +-----------------------+------------+
  115. |missing-docstring      |5           |
  116. +-----------------------+------------+
  117. |too-few-public-methods |2           |
  118. +-----------------------+------------+
  119. |old-style-class        |1           |
  120. +-----------------------+------------+
  121. |old-raise-syntax       |1           |
  122. +-----------------------+------------+
  123.  
  124.  
  125.  
  126. Global evaluation
  127. -----------------
  128. Your code has been rated at 5.15/10
  129.  
  130. Statistics by type
  131. ------------------
  132.  
  133. +---------+-------+-----------+-----------+------------+---------+
  134. |type     |number |old number |difference |%documented |%badname |
  135. +=========+=======+===========+===========+============+=========+
  136. |module   |1      |1          |=          |0.00        |0.00     |
  137. +---------+-------+-----------+-----------+------------+---------+
  138. |class    |2      |2          |=          |0.00        |0.00     |
  139. +---------+-------+-----------+-----------+------------+---------+
  140. |method   |3      |3          |=          |100.00      |0.00     |
  141. +---------+-------+-----------+-----------+------------+---------+
  142. |function |2      |2          |=          |0.00        |0.00     |
  143. +---------+-------+-----------+-----------+------------+---------+
  144.  
  145.  
  146.  
  147. Duplication
  148. -----------
  149.  
  150. +-------------------------+------+---------+-----------+
  151. |                         |now   |previous |difference |
  152. +=========================+======+=========+===========+
  153. |nb duplicated lines      |0     |0        |=          |
  154. +-------------------------+------+---------+-----------+
  155. |percent duplicated lines |0.000 |0.000    |=          |
  156. +-------------------------+------+---------+-----------+
  157.  
  158.  
  159. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement