Skip to content

Commit 39ba996

Browse files
committed
assertion.rewrite: use ast.NameConstant(None) directly
`ast.parse("None")` was added/used in 3e6f1fa for differences between Python 2/3, but we do not support py2 anymore.
1 parent 300f785 commit 39ba996

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/_pytest/assertion/rewrite.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
PYC_EXT = ".py" + (__debug__ and "c" or "o")
3434
PYC_TAIL = "." + PYTEST_TAG + PYC_EXT
3535

36+
AST_IS = ast.Is()
37+
AST_NONE = ast.NameConstant(None)
38+
3639

3740
class AssertionRewritingHook:
3841
"""PEP302/PEP451 import hook which rewrites asserts."""
@@ -854,10 +857,7 @@ def warn_about_none_ast(self, node, module_path, lineno):
854857
internally already.
855858
See issue #3191 for more details.
856859
"""
857-
858-
# Using parse because it is different between py2 and py3.
859-
AST_NONE = ast.parse("None").body[0].value
860-
val_is_none = ast.Compare(node, [ast.Is()], [AST_NONE])
860+
val_is_none = ast.Compare(node, [AST_IS], [AST_NONE])
861861
send_warning = ast.parse(
862862
"""\
863863
from _pytest.warning_types import PytestAssertRewriteWarning

0 commit comments

Comments
 (0)