Skip to content

Conversation

@zenlyj
Copy link
Contributor

@zenlyj zenlyj commented Jan 4, 2026

Type of Changes

Type
πŸ› Bug fix
βœ“ ✨ New feature
πŸ”¨ Refactoring
πŸ“œ Docs

Description

Add a new EqualityConstraint to support narrowing of inferred values based on equality (==) and inequality (!=) comparisons.

The constraint currently handles:

  • Comparison between constants
  • Comparison between callables (e.g. classes, functions, lambdas)

Refs
pylint-dev/pylint#3632
pylint-dev/pylint#3633

@codecov
Copy link

codecov bot commented Jan 4, 2026

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 93.31%. Comparing base (d4a7e63) to head (e369324).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2927      +/-   ##
==========================================
+ Coverage   93.29%   93.31%   +0.01%     
==========================================
  Files          92       92              
  Lines       11266    11292      +26     
==========================================
+ Hits        10511    10537      +26     
  Misses        755      755              
Flag Coverage Ξ”
linux 93.17% <100.00%> (+0.01%) ⬆️
pypy 93.31% <100.00%> (+0.01%) ⬆️
windows 93.29% <100.00%> (+0.01%) ⬆️

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

Files with missing lines Coverage Ξ”
astroid/constraint.py 100.00% <100.00%> (ΓΈ)
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zenlyj
Copy link
Contributor Author

zenlyj commented Jan 4, 2026

The referenced issues are no longer flagged by pylint, probably due to the use of safe_infer(). However, the following false positive is still present:

"""docstring"""

class PV1Axis():
    """Single-axis tracking PV."""
    def __init__(self, polygon, capacity, filename, column, build_limit=None, label='PV'):
        pass

class Biofuel():
    """Model of open cycle gas turbines burning biofuel."""
    def __init__(self, polygon, capacity, label='biofuel'):
        pass

g = PV1Axis
if g == Biofuel:
    g(0, 100)  # E1120: No value for argument 'filename'/'column' in constructor call (no-value-for-parameter)

@zenlyj zenlyj force-pushed the equality-constraint branch 2 times, most recently from 2a290ff to bbe78f4 Compare January 4, 2026 15:37
Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

@jacobtylerwalls Do you have time to review this? I consider you domain expert on the constraints.

It LGTM, but I might be missing something.

Thanks @zenlyj for this PR!

@jacobtylerwalls jacobtylerwalls self-requested a review January 5, 2026 19:57
@jacobtylerwalls jacobtylerwalls added this to the 4.1.0 milestone Jan 5, 2026
Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Thanks πŸ‘

I was sitting on this one for a bit because I thought I might resuscitate my effort to adding a github workflow to run the pylint primer on astroid PRs, but I just didn't get there yet.

@zenlyj zenlyj force-pushed the equality-constraint branch from bbe78f4 to 3bb8317 Compare February 1, 2026 12:30
Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Thanks πŸ‘, just a teeny polish question.

y #@
""")

for node in (node1, node2, node3, node4):
Copy link
Member

Choose a reason for hiding this comment

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

Is there a pytest-idiomatic way to show the node that failed in the assertion?

Copy link
Member

Choose a reason for hiding this comment

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

I usually add info about the node in the assert message when doing this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I've added some info to identify the node that fails. The message looks something like this:

image

Let me know if the message needs to be refined

@zenlyj zenlyj force-pushed the equality-constraint branch from 65ea115 to 3536542 Compare February 3, 2026 17:25
Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Thanks!

@jacobtylerwalls jacobtylerwalls merged commit 55f76d8 into pylint-dev:main Feb 6, 2026
19 checks passed
@zenlyj zenlyj deleted the equality-constraint branch February 7, 2026 01:48
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.

4 participants