Allow type inference for list.pop() - #45
Closed
neilccbrown wants to merge 1 commit into
Closed
neilccbrown wants to merge 1 commit into
neilccbrown wants to merge 1 commit into
Conversation
pop() was hard-coded to return the list type itself instead of the item type, so e.g. get_actors().pop().remove() resolved .remove() against list.remove(x) instead of the actual item class's remove(), leaking the wrong signature into autocomplete. Added an ECHO_SELF_ITEM_TYPE marker so a method's return type can echo its receiver's item type (existing ECHO_ITEM_TYPE only echoes an argument's item type, which methods don't have access to). Also fixed append/extend/insert/remove/reverse/sort, which had the same hard-coded-to-self bug but should return None. Mirrored the fix into the equivalent (currently unreachable) code in tigerpython.parser.types for consistency. Regenerated release JS/mjs.
Owner
|
I am a bit unsure whether it makes sense to actually merge this in. Actually, I have been working on a more flexible solution recently, which solves the same problem. My approach was to introduce a new class On the other hand, you are absolutely correct that the return types of various methods are clearly wrong. |
Contributor
Author
|
Is that the work on the "dev-tk" branch? I'm happy to try using that approach instead and see about adapting it for the list method here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pop() was hard-coded to return the list type itself instead of the item type. Several other list methods were also incorrectly returning the list type (unless I've misunderstood?). Most of them can be changed to returning None, but it would be nice for us if pop() had correct inference. To this end, added an ECHO_SELF_ITEM_TYPE marker so a method's return type can echo its receiver's item type (the existing ECHO_ITEM_TYPE only echoes an argument's item type, which methods don't have access to).
Also mirrored the fix into the equivalent (currently unreachable, according to the AI?) code in tigerpython.parser.types for consistency.