Skip to content

Conversation

@ionelmc
Copy link
Member

@ionelmc ionelmc commented Jun 6, 2025

No description provided.

@ionelmc ionelmc changed the title Add reproducer for #693. Add default filterwarning configuration Jun 11, 2025
@ionelmc ionelmc merged commit f69166a into master Jun 11, 2025
180 of 182 checks passed
@ionelmc ionelmc deleted the issue-693 branch June 11, 2025 21:53
if TYPE_CHECKING:
from .engine import CovController

COVERAGE_SQLITE_WARNING_RE = re.compile('unclosed database in <sqlite3.Connection object at', re.I)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; with conditions:

NIT - the pattern string could have be abstracted for use later
Suggested change
COVERAGE_SQLITE_WARNING_RE = re.compile('unclosed database in <sqlite3.Connection object at', re.I)
COVERAGE_SQLITE_WARNING_STUB = 'unclosed database in <sqlite3.Connection object at'
COVERAGE_SQLITE_WARNING_RE = re.compile(COVERAGE_SQLITE_WARNING_STUB, re.I)

and later used to simplify:

 for _, message, category, _, _ in warnings.filters: if category is ResourceWarning and message == COVERAGE_SQLITE_WARNING_RE: break else: warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning)

with the patch:

 for _, message, category, _, _ in warnings.filters: if category is ResourceWarning and message == COVERAGE_SQLITE_WARNING_RE: break else: - warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning) + warnings.filterwarnings('default', COVERAGE_SQLITE_WARNING_STUB, ResourceWarning)

yielding:

 for _, message, category, _, _ in warnings.filters: if category is ResourceWarning and message == COVERAGE_SQLITE_WARNING_RE: break else: warnings.filterwarnings('default', COVERAGE_SQLITE_WARNING_STUB, ResourceWarning)
if category is ResourceWarning and message == COVERAGE_SQLITE_WARNING_RE:
break
else:
warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; with continued conditions:

NIT - Could be more DRY

As mentioned already, this string could be set with the RE variable so that only the base string need be ever updated 🤷

e.g.,

COVERAGE_SQLITE_WARNING_STUB = 'unclosed database in <sqlite3.Connection object at' COVERAGE_SQLITE_WARNING_RE = re.compile(COVERAGE_SQLITE_WARNING_STUB, re.I)

and refactor this line to:

Suggested change
warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning)
warnings.filterwarnings('default', COVERAGE_SQLITE_WARNING_STUB, ResourceWarning)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants