Skip to content

Fix typing of Condition.each/for_each to return Condition[Collection] (#541) - #684

Open
dweep-js wants to merge 1 commit into
yashaka:masterfrom
dweep-js:fix-541-each-typing
Open

dweep-js wants to merge 1 commit into
yashaka:masterfrom
dweep-js:fix-541-each-typing

Conversation

@dweep-js

@dweep-js dweep-js commented Jul 2, 2026

Copy link
Copy Markdown

Fixes #541.

Problem

Condition.each and Condition.for_each were typed to return
Condition[Iterable[E]]. Because Condition is invariant in its generic
parameter, PyCharm's type checker couldn't resolve
Condition[Iterable[Element]] against the Condition[Collection] bound
expected by a collection entity's .should() — even though Collection
is itself an Iterable[Element] at runtime. This produced a false-positive
type mismatch warning in PyCharm for code like:

ss('').should(have.text('').each)

Fix

Changed both return type annotations (for_each and the each property)
from Condition[Iterable[E]] to Condition[Collection], matching what
.should() actually expects on collection entities. Collection is
imported under TYPE_CHECKING to avoid a circular import with
entity.py.

Verification

  • mypy selene/core/condition.py — no issues
  • Confirmed via reveal_type() that Condition[Element].each now
    resolves to Condition[Collection] (previously
    Condition[Iterable[Element]])
  • pytest tests/unit — all 62 tests pass
  • black --check — clean

I don't have PyCharm available to visually confirm the IDE warning
disappears, but the mypy reveal_type output confirms the underlying
type resolution now matches what .should() expects. Would appreciate
a maintainer with PyCharm doing a final visual check on
ss('').should(have.text('').each).

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.23%. Comparing base (d0d7484) to head (03b0b27).

Files with missing lines Patch % Lines
selene/core/condition.py 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #684      +/-   ##
==========================================
- Coverage   69.27%   69.23%   -0.05%     
==========================================
  Files          50       50              
  Lines        3339     3341       +2     
  Branches      386      387       +1     
==========================================
  Hits         2313     2313              
- Misses        932      933       +1     
- Partials       94       95       +1     
Flag Coverage Δ
regression 68.27% <60.00%> (-0.05%) ⬇️
unit 47.50% <40.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
selene/core/condition.py 68.33% <60.00%> (-0.77%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix PyCharm 'Property each of selene.core.condition.Condition' type resolution for collections

1 participant