Skip to content

[refactor] Use match case instead of isinstance calls when the readability is better - #3431

Open
Pierre-Sassoulas wants to merge 11 commits into
pylint-dev:mainfrom
Pierre-Sassoulas:match-case-isinstance
Open

Pierre-Sassoulas wants to merge 11 commits into
pylint-dev:mainfrom
Pierre-Sassoulas:match-case-isinstance

Conversation

@Pierre-Sassoulas

@Pierre-Sassoulas Pierre-Sassoulas commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Type of Changes

Type
✓ 🔨 Refactoring

Description

Use match case when replacing isinstance calls result in a net positive line count.

@Pierre-Sassoulas Pierre-Sassoulas added Maintenance Discussion or action around maintaining astroid or the dev workflow Skip news 🔇 This change does not require a changelog entry labels Oct 22, 2026
@codspeed

codspeed Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.78%

1 warning

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

❌ 3 regressed benchmarks
⏩ 1 skipped benchmark1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_bench_endtoend_parse_flask 5.2 s 5.5 s -5.39%
❌ test_bench_endtoend_walk_infer_flask 23.1 s 24.2 s -4.7%
❌ test_bench_endtoend_walk_infer_black 35.8 s 37.3 s -4.24%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Pierre-Sassoulas:match-case-isinstance (6a82cc1) with main (b5e78cd)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.89474% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.18%. Comparing base (af39fd7) to head (6a82cc1).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
astroid/nodes/scoped_nodes/scoped_nodes.py 87.50% 1 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (97.89%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3431      +/-   ##
==========================================
+ Coverage   90.96%   91.18%   +0.21%     
==========================================
  Files          93       93              
  Lines       11800    11804       +4     
  Branches     1941     1933       -8     
==========================================
+ Hits        10734    10763      +29     
+ Misses        747      734      -13     
+ Partials      319      307      -12     
Flag Coverage Δ
linux 90.85% <97.89%> (+0.21%) ⬆️
pypy 91.18% <97.89%> (+0.21%) ⬆️
windows 91.01% <97.89%> (+0.21%) ⬆️

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

Files with missing lines Coverage Δ
astroid/brain/brain_builtin_inference.py 92.19% <100.00%> (+0.79%) ⬆️
astroid/brain/brain_dataclasses.py 91.90% <100.00%> (+0.89%) ⬆️
astroid/brain/brain_re.py 100.00% <100.00%> (ø)
astroid/brain/brain_regex.py 100.00% <100.00%> (ø)
astroid/brain/brain_typing.py 82.53% <100.00%> (-0.11%) ⬇️
astroid/builder.py 92.67% <100.00%> (+0.03%) ⬆️
astroid/constraint.py 100.00% <100.00%> (+1.05%) ⬆️
astroid/helpers.py 91.25% <100.00%> (+0.05%) ⬆️
astroid/nodes/_base_nodes.py 95.37% <100.00%> (+0.01%) ⬆️
astroid/protocols.py 90.16% <100.00%> (+0.01%) ⬆️
... and 2 more

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Pierre-Sassoulas Pierre-Sassoulas added the Blocked 🚧 A PR or issue blocked by another PR or issue label Oct 22, 2026
@Pierre-Sassoulas

Copy link
Copy Markdown
Member Author

Blocked by performance issue in match case fixed by Marc in python 3.13 if I remember correctly.

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

Blocked 🚧 A PR or issue blocked by another PR or issue Maintenance Discussion or action around maintaining astroid or the dev workflow Skip news 🔇 This change does not require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant