From 1da54b45469f17ae360a49d8ae3a504642a4b9d9 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 9 Sep 2023 00:32:07 +0200 Subject: [PATCH] Revert "Use an enum for sentinel" This reverts commit 35771f643d6e26d66202c3be3202a058af8125f9. --- src/_pytest/assertion/rewrite.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index f894f2be3..32e962536 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -14,7 +14,6 @@ import sys import tokenize import types from collections import defaultdict -from enum import Enum from pathlib import Path from pathlib import PurePath from typing import Callable @@ -54,11 +53,7 @@ PYTEST_TAG = f"{sys.implementation.cache_tag}-pytest-{version}" PYC_EXT = ".py" + (__debug__ and "c" or "o") PYC_TAIL = "." + PYTEST_TAG + PYC_EXT - -class ScopeEndMarkerType(Enum): - """Special marker that denotes we have just left a function or class definition.""" - - ScopeEndMarker = 1 +_SCOPE_END_MARKER = object() class AssertionRewritingHook(importlib.abc.MetaPathFinder, importlib.abc.Loader): @@ -733,13 +728,13 @@ class AssertionRewriter(ast.NodeVisitor): # Collect asserts. self.scope = (mod,) - nodes: List[Union[ast.AST, ScopeEndMarkerType]] = [mod] + nodes: List[Union[ast.AST, object]] = [mod] while nodes: node = nodes.pop() if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)): self.scope = tuple((*self.scope, node)) - nodes.append(ScopeEndMarkerType.ScopeEndMarker) - if node is ScopeEndMarkerType.ScopeEndMarker: + nodes.append(_SCOPE_END_MARKER) + if node == _SCOPE_END_MARKER: self.scope = self.scope[:-1] continue assert isinstance(node, ast.AST)