Comments (2)
Thanks for the report. This is a good case for extending astroid's constraint framework. I'm showing this is fixed with:
diff --git a/astroid/constraint.py b/astroid/constraint.py
index 08bb80e3..57b41701 100644
--- a/astroid/constraint.py
+++ b/astroid/constraint.py
@@ -63,6 +63,8 @@ class NoneConstraint(Constraint):
Negate the constraint based on the value of negate.
"""
+ if isinstance(expr, nodes.Attribute):
+ return cls(node=node, negate=negate)
if isinstance(expr, nodes.Compare) and len(expr.ops) == 1:
left = expr.left
op, right = expr.ops[0]
@@ -99,10 +101,10 @@ def get_constraints(
constraints_mapping: dict[nodes.If, set[Constraint]] = {}
while current_node is not None and current_node is not frame:
parent = current_node.parent
- if isinstance(parent, nodes.If):
+ if isinstance(parent, (nodes.If, nodes.IfExp)):
branch, _ = parent.locate_child(current_node)
constraints: set[Constraint] | None = None
- if branch == "body":
+ if branch in ("body", "test"):
constraints = set(_match_constraint(expr, parent.test))
elif branch == "orelse":
constraints = set(_match_constraint(expr, parent.test, invert=True))
from pylint.
That patch is probably a little too wide, but I hope it's on the right direction.
from pylint.
Related Issues (20)
- Pylint does not discover a NoReturn method in certain cases to avoid "inconsistent-return-statements" HOT 3
- False positive for `use-yield-from` for generators yielding from iterators
- pylint crashing with `concurrent.futures.process.BrokenProcessPool` HOT 3
- E0606: detect validation done in external function HOT 6
- Crash ``Building error when trying to create ast representation of module 'aws_cp.__init__'`` HOT 1
- Crash ``Building error when trying to create ast representation of module 'aws_cp.aws'``
- Crash ``Building error when trying to create ast representation of module 'aws_cp.app'``
- pylint cannot find third-party packages in virtual environment HOT 3
- False Positive W0143-comparison-with-callable when using derived property descriptors
- Documentation about `class-const` needs to be updated.
- PEP 695: Type Parameter Syntax HOT 1
- pylint not finding the tox.ini config HOT 12
- PyTest FixtureRequest
- Feature Request: Have multiple types for a naming-style HOT 2
- Support disabling possibly-used-before-assignment in-line for specific variables HOT 2
- `@overload` causes `missing-param-doc` despite parameter being documented HOT 1
- False positive unnecessary-negation for float comparison HOT 2
- Import error with Python 3.11 HOT 5
- Pylint is not smart enough when analyzes functions returning coroutine. HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pylint.