Comments (8)
It looks like this bug was introduced in version 1.5.0. I tested previous versions and version 1.4.1 is the last one that works as expected.
from mypy.
I've found the culprit - 3bf8521.
from mypy.
@ikonst please take a look
file mypy/checker.py line 467-
- if (
- self.binder.is_unreachable()
- and self.should_report_unreachable_issues()
- and not self.is_raising_or_empty(d)
- ):
- self.msg.unreachable_statement(d)
- break
- self.accept(d)
+ if self.binder.is_unreachable():
+ if not self.should_report_unreachable_issues():
+ break
+ if not self.is_noop_for_reachability(d):
+ self.msg.unreachable_statement(d)
+ break
+ else:
+ self.accept(d)
In the previous version it was possible for self.accept(d) to run even if the self.binder.is_unreachable() was True (eg when self.should_report_unreachable_issues() was False). After your changes when self.binder.is_unreachable() is True there is no possibility to run self.accept(d).
In the example I provided (the one with lambda function) the line after lambda is marked as unreachable which I think is also not right. Nevertheless in versions before 1.5.0 this is not an issue and the next lines are checked.
from mypy.
You can see me discussing in the PR that maybe the right thing to do is not to avoid type checking unreachable code. I just don't think I ever got to make that change since it seemed larger.
from mypy.
How do you think we should proceed? I think that mypy falsely marks the statement after this lambda expression as an unreachable code. So that is the actual bug. In the older versions it went unnoticed though and after your change it stopped checking the presumably unreachable code. I think it shouldn’t be marked as u reachable in the first place. What do you think @ikonst?
from mypy.
Yeah, fixing the false unreachable is probably the way to go.
from mypy.
By moving the code into a function (and adjusting for syntax modernization), I can reproduce the same bug all the way back to the original introduction of NoReturn
in 9406886 = v0.500~45.
from mypy_extensions import NoReturn
def foo():
# type: () -> NoReturn
raise
def main():
# type: () -> None
f = lambda _: foo() # when this line is commented mypy works as expected
bar = "baz" # type: int
from mypy.
It looks like the problem is that ExpressionChecker.visit_lambda_expr
never pushes a new Frame
onto self.chk.binder
, and unreachability is associated with a Frame
so it leaks outside the lambda
body.
Indeed, this effect is noted in a comment there, although the chosen solution only works around unreachability from the implicit return
statement and not other kinds of unreachability:
Lines 5227 to 5235 in 43a605f
from mypy.
Related Issues (20)
- Crash (stack overflow/segfault): `assert_type(<type>.__new__, SomeProtocol)` involving `Self` HOT 1
- INTERNAL ERROR during type check
- Failed to resolve the boundary type in a PEP 695 new style definition HOT 2
- (🎁) Error when `__get__` returns incompatible type
- Use of __iter__ and __next__ does not confer all Iterator protocol abilities HOT 4
- Duplicate module error with stub files
- Overriding methods with partially generic signatures leads to mypy errors
- Mypy error "__ does not return a value" when using `lambda` with multiple expression HOT 1
- A generic function taking a TypedDict type erroneously reports missing __required_keys__
- A Bug come from using the Customtkinter HOT 1
- There is a bug in `exclue` ?
- Check for (obviously) non-side-effectful Expr HOT 3
- Match exhaustion fails incorrectly when matching same option twice.
- possibly-undefined false negative for variable annotation HOT 1
- PEP-681 - Inheriting class doesn't recognize kw_only=True from parent class HOT 1
- False positive on function call with walrus operator
- Need help annotating class with dynamic inheritance
- `ignore-missing-imports` runs afoul of `no-any-return` HOT 2
- Having a function that takes `Optional[T]` as an input and returns `T` (A type var) works incorrectly if T is an union HOT 1
- possibly-undefined not catching unbound variable in try/finally block
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 mypy.