Skip to content

Fix pseudo-class specificity calculation per CSS spec - #76

Merged
jaraco merged 5 commits into
mainfrom
copilot/update-specificity-for-pseudo-classes
Apr 27, 2026
Merged

Fix pseudo-class specificity calculation per CSS spec#76
jaraco merged 5 commits into
mainfrom
copilot/update-specificity-for-pseudo-classes

Conversation

CopilotAI commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Pseudo-classes (:hover, :last-child, :nth-child(), etc.) were not counted in specificity at all, violating the CSS spec which places them in the class weight column (column c).

importcssutilss=cssutils.css.Selector()
s.selectorText='.table > :last-child > tr:last-child > *'s.specificity# was (0, 1, 1), should be (0, 0, 3, 1)

Changes

  • cssutils/css/selector.py — In New.append(), add 'pseudo-class' to the condition incrementing specificity[2]. Pseudo-elements, :not() (which contributes no specificity itself), and expression content inside pseudo-class functions are all unaffected.
  • tests/test_selector.py — Correct a:hover expectation (0,0,0,1)(0,0,1,1); add test cases for :last-child, :nth-child(), and the issue's example selector.

CopilotAI linked an issue Apr 21, 2026 that may be closed by this pull request
CopilotAI changed the title [WIP] Update specificity calculation to support pseudo-classesFix pseudo-class specificity calculation per CSS specApr 21, 2026
CopilotAI requested a review from jaracoApril 21, 2026 01:07
@jaraco
jaraco marked this pull request as ready for review April 27, 2026 15:51
@jaraco

Copy link
Copy Markdown
Owner

@copilot remove the .gitignore and LICENSE files; those are managed outside the repo.

CopilotAI commented Apr 27, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot remove the .gitignore and LICENSE files; those are managed outside the repo.

Done — removed both .gitignore and LICENSE in 9677bb1.

@jaraco

Copy link
Copy Markdown
Owner

@copilot Add a news fragment using towncrier (or simulating towncrier). Make it a minor scope.

CopilotAI commented Apr 27, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot Add a news fragment using towncrier (or simulating towncrier). Make it a minor scope.

Added newsfragments/76.minor.rst in 5bf6402.

@jaraco
jaraco merged commit 20bc2dc into mainApr 27, 2026
30 checks passed
@jaraco
jaraco deleted the copilot/update-specificity-for-pseudo-classes branch April 27, 2026 19:36
Sign up for freeto 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.

Update specificity to support pseudo-classes

2 participants

@jaraco