Skip to content

Commit 9a5ddd8

Browse files
author
rocky
committed
Lint
1 parent 1c531d4 commit 9a5ddd8

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed

xdis/marsh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def w_long(self, x):
139139
self._write(a + b + c + d)
140140

141141
def w_short(self, x):
142-
self._write(chr((x) & 0xFF))
142+
self._write(chr(x & 0xFF))
143143
self._write(chr((x >> 8) & 0xFF))
144144

145145
def dump_none(self, x):

xdis/std.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717

1818
"""
19-
Provide the same API as Python 3.x so xdis can be used as a drop in
20-
replacement for dis. This will provide a dis module with support for the
21-
Python version being run.
19+
Provide the same API as Python 3.x so xdis can be used as a drop-in
20+
replacement for ``dis``.
21+
22+
This will provide ``dis`` module with support for the Python version being run.
2223
2324
Why would you want this? The main reason is if you want a compatibility shim
24-
for supporting the more advanced Python 3 dis API (being able to iterate through
25-
opcodes, supplying a custom file to dump the dis to) across python versions, for
25+
for supporting the more advanced Python3 dis API. That is, to be able to iterate through
26+
opcodes, supplying a custom file to dump the dis to across python versions. For
2627
example:
2728
2829
import xdis.std as dis
@@ -31,7 +32,7 @@
3132
for op in dis.Bytecode('for i in range(10): pass'):
3233
print(op)
3334
34-
There is also the ability to generate a std api for a specific version, for example:
35+
There is also the ability to generate a std api for a specific version. For example:
3536
3637
from xdis.std import make_std_api
3738
dis = make_std_api(2.4)
@@ -88,12 +89,12 @@ def __init__(self, python_version=sys.version_info, variant=VARIANT):
8889
self.HAVE_ARGUMENT = opc.HAVE_ARGUMENT
8990

9091
class Bytecode(_Bytecode):
91-
"""The bytecode operations of a piece of code
92+
"""The bytecode operations in a piece of code
9293
9394
Instantiate this with a function, method, string of code, or a code object
9495
(as returned by compile()).
9596
96-
Iterating over this yields a bytecode operation as Instruction instances.
97+
Iterating over these yields a bytecode operation as Instruction instances.
9798
"""
9899

99100
def __init__(self, x, first_line=None, current_offset=None, opc=None):
@@ -248,26 +249,27 @@ def findlabels(self, code):
248249
"""Detect all offsets in a byte code which are jump targets.
249250
250251
Return the list of offsets.
251-
252252
"""
253253
return self.opc.findlabels(code, self.opc)
254254

255255

256256
def make_std_api(python_version=sys.version_info, variant=VARIANT):
257257
"""
258-
Generate an object which can be used in the same way as the python
259-
standard dis module. The difference is that the generated 'module' can be
258+
Generate an object which can be used in the same way as the Python
259+
standard ``dis`` module.
260+
261+
The difference is that the generated 'module' can be
260262
used to disassemble byte / word code from a different python version than
261263
the version of the interpreter under which we are running.
262264
263265
:param python_version: Generate a dis module for this version of python
264266
(defaults to the currently running python version.)
265267
:param variant: The string denoting the variant of the python version
266-
being run, for example 'pypy' or 'alpha0', 'rc1' etc,,
267-
or None to auto detect based on the currently running
268+
being run, for example 'pypy' or 'alpha0', 'rc1' etc.,
269+
or None to auto-detect based on the currently running
268270
interpreter.
269271
270-
:return: object which can be used like the std dis module.
272+
:return: An Object which can be used like the std ``dis`` module.
271273
"""
272274
if isinstance(python_version, float):
273275
major = int(python_version)

xdis/unmarshal.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
a different version than the currently-running Python.
2323
2424
When the running interpreter and the read-in bytecode are the same,
25-
you can simply use Python's built-in marshal.loads() to produce a code
26-
object
25+
you can use Python's built-in ``marshal.loads()`` to produce a code
26+
object.
2727
"""
2828

2929
import io
@@ -54,14 +54,14 @@ def long(n):
5454
FLAG_REF = 0x80
5555

5656

57-
# The keys in following dictionary are an unmashal codes, like "s",
58-
# "c", "<", etc. the values of the dictionary are names of routines
57+
# The keys in the following dictionary are unmarshal codes, like "s",
58+
# "c", "<", etc. The values of the dictionary are names of routines
5959
# to call that do the data unmarshaling.
6060
#
61-
# Note: we could eliminate the parameters, if this were all inside a
61+
# Note: we could eliminate the parameters if this were all inside a
6262
# class. This might be good from an efficiency standpoint, and bad
6363
# from a functional-programming standpoint. Pick your poison.
64-
# EDIT: I'm choosing efficiency over functional-programming.
64+
# EDIT: I'm choosing efficiency over functional programming.
6565
UNMARSHAL_DISPATCH_TABLE = {
6666
"0": "C_NULL",
6767
"N": "None",
@@ -116,10 +116,10 @@ def compat_str(s: Union[str, bytes]) -> Union[str, bytes]:
116116

117117
def compat_u2s(u):
118118
if PYTHON_VERSION_TRIPLE < (3, 0):
119-
# See also unaccent.py which can be found using google. I
119+
# See also ``unaccent.py`` which can be found using Google. I
120120
# found it and this code via
121121
# https://www.peterbe.com/plog/unicode-to-ascii where it is a
122-
# dead link. That can potentially do better job in converting accents.
122+
# dead link. That can potentially do a better job in converting accents.
123123
s = unicodedata.normalize("NFKD", u)
124124
try:
125125
return s.encode("ascii")
@@ -139,7 +139,7 @@ def __init__(self, fp, magic_int, bytes_for_s, code_objects={}):
139139
3: [3.4a0, 3.4a3) (self.magic_int: 3250 until 3280)
140140
4: [3.4a3, current) (self.magic_int: 3280 onwards)
141141
142-
In Python 3 a bytes type is used for strings.
142+
In Python 3, a ``bytes`` type is used for strings.
143143
"""
144144
self.fp = fp
145145
self.magic_int = magic_int
@@ -167,7 +167,7 @@ def __init__(self, fp, magic_int, bytes_for_s, code_objects={}):
167167

168168
def load(self):
169169
"""
170-
marshal.load() written in Python. When the Python bytecode magic loaded is the
170+
``marshal.load()`` written in Python. When the Python bytecode magic loaded is the
171171
same magic for the running Python interpreter, we can simply use the
172172
Python-supplied marshal.load().
173173
@@ -316,8 +316,8 @@ def t_binary_complex(self, save_ref, bytes_for_s=False):
316316
# Note: could mean bytes in Python3 processing Python2 bytecode
317317
def t_string(self, save_ref, bytes_for_s: bool):
318318
"""
319-
In Python3 this is a bytes types. In Python2 it is a string.
320-
`bytes_for_s` distinguishes what we need.
319+
In Python3, this is a ``bytes`` type. In Python2, it is a string type;
320+
``bytes_for_s`` distinguishes what we need.
321321
"""
322322
strsize = unpack("<i", self.fp.read(4))[0]
323323
s = self.fp.read(strsize)

xdis/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Much of this is borrowed from Python's Lib/dis.py
1+
# Much of this is borrowed from Python's ``Lib/dis.py``.
22

33
from math import copysign
44
from typing import Dict
@@ -57,7 +57,7 @@ def num2code(num):
5757
(v, k) for (k, v) in COMPILER_FLAG_NAMES.items()
5858
)
5959

60-
# Allow us to access by just name, prefixed with CO., e.g
60+
# Allow us to access by just name, prefixed with CO., e.g.,
6161
# CO_OPTIMIZED, CO_NOFREE.
6262
globals().update(dict(("CO_" + k, v) for (k, v) in COMPILER_FLAG_BIT.items()))
6363

xdis/verify.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def dump_compile(codeobject, filename, timestamp, magic):
4141
"""Write ``codeobject`` as a byte-compiled file.
4242
4343
Arguments:
44-
codeobject: code object
45-
filename: bytecode file to write
46-
timestamp: timestamp to put in file
44+
codeobject: Code object
45+
filename: ytecode file to write
46+
timestamp: Tme stamp to put in file
4747
magic: Python bytecode magic
4848
"""
4949
# Atomically write the pyc/pyo file. Issue #13146.

0 commit comments

Comments
 (0)