You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Catch TypeVisitor subclasses with unimplemented abstract methods #730
Issue #638 was a pain to find because the root cause is an unimplemented abstract method which silently returns None and somewhere down the line causes type checking to fail. It would be better to check this explicitly. The following shows that this is done for one of the abstract methods: https://github.com/JukkaL/mypy/blob/bbb2dd4f07f995a4b28b8044fa91aa97960fe192/mypy/types.py#L532. There are two potential solutions: 1) use abc's @AbstractMethod decorator, 2) raise an error directly in TypeVisitor.
Ensures that future implementations and changes catch subclasses which do not implement the abstract methods, but requires adding implementations for all of the abstract methods to existing subclasses which are missing them. As there are a few, it would probably be simplest to raise an error there instead of providing the complete implementation, which raises the question: why not just use 2) straight off the bat?
It appears as though there is a common pattern of unimplemented abstract methods (visit_star_type, visit_overloaded, visit_error_type, visit_erased_type), I figured that maybe they had been added after the initial implementation of all visitors, and don't appear in the test cases and as such haven't been caught. In total there are about 25 subclasses which do not implement all abstract methods, mostly it is either visit_star_type or visit_overloaded which are unimplemented.
The current implementation is just sloppy, and is inherited from early pre-mypy days when there were no abstract methods.
Using @abstractmethod is probably the best option, as missing implementations can then be caught statically. Trying to catch all of these errors using test cases is an uphill battle.
Activity
o11c commentedon Jul 27, 2015
I am suspicious of any visitors that can meaningfully work without full implementations.
Perhaps there is a need for more specific visitors?
JamesGuthrie commentedon Jul 28, 2015
It appears as though there is a common pattern of unimplemented abstract methods (visit_star_type, visit_overloaded, visit_error_type, visit_erased_type), I figured that maybe they had been added after the initial implementation of all visitors, and don't appear in the test cases and as such haven't been caught. In total there are about 25 subclasses which do not implement all abstract methods, mostly it is either visit_star_type or visit_overloaded which are unimplemented.
JukkaL commentedon Aug 4, 2015
The current implementation is just sloppy, and is inherited from early pre-mypy days when there were no abstract methods.
Using
@abstractmethodis probably the best option, as missing implementations can then be caught statically. Trying to catch all of these errors using test cases is an uphill battle.Catch incomplete TypeVisitor implementations
JamesGuthrie commentedon Aug 4, 2015
I've opened a PR to get the ball rolling.
As mentioned in the PR, Subclasses with incomplete implementations are:
Catch incomplete TypeVisitor implementations
Raise error on unimplemented abstract method call
Add SameTypeVisitor.visit_overloaded() implementation
Add visit_overloaded() to TypeVisitor.
Add visit_overloaded to TypeQuery
add visit_star_type to TypeAnalyserPass3
add visit_overloaded to ConstraintBuilderVisitor
Add SameTypeVisitor.visit_overloaded() implementation
Add visit_overloaded() to TypeTranslator.
13 remaining items
Add SameTypeVisitor.visit_overloaded() implementation
Add visit_overloaded() to TypeTranslator.
Add visit_overloaded() to TypeQuery
add visit_star_type() to TypeAnalyserPass3
add visit_overloaded() to ConstraintBuilderVisitor
Use inheritance to allow most TypeVisitors not to deal with "syntheti…
Use inheritance to allow most TypeVisitors not to deal with "syntheti…
jbsiddall commentedon Apr 13, 2018
Is there any update on this? mypy 0.580 is stil showing this error for code:
for item in {int}: passJelleZijlstra commentedon Apr 13, 2018
Are you sure you're on the right issue? This one is talking about an internal problem in mypy as far as I can tell.
Make TypeVisitor and SyntheticTypeVisitor fully abstract
Make TypeVisitor and SyntheticTypeVisitor (almost) fully abstract (#7312
Make TypeVisitor and SyntheticTypeVisitor (almost) fully abstract (py…