Fix reporting location in aliased types.#12745
Conversation
| reveal_type(a) # N: Revealed type is "other.array[Any, other.dtype[builtins.float]]" | ||
|
|
||
| [out] | ||
| main:2: error: Type argument "float" of "dtype" must be a subtype of "generic" |
There was a problem hiding this comment.
output with the current master is
main:12: error: Type argument "float" of "dtype" must be a subtype of "generic" (diff)
where 12 is the line number in other.py but is used as a reference with main.py.
There was a problem hiding this comment.
with --pretty flag the test fails on master as
[gw0] linux -- Python 3.8.10 /home/miha/foss/mypy/venv/bin/python3
data: /home/miha/foss/mypy/test-data/unit/check-generics.test:651:
/home/miha/foss/mypy/mypy/test/testcheck.py:141: in run_case
self.run_case_once(testcase)
/home/miha/foss/mypy/mypy/test/testcheck.py:199: in run_case_once
res = build.build(sources=sources,
/home/miha/foss/mypy/mypy/build.py:181: in build
result = _build(
/home/miha/foss/mypy/mypy/build.py:257: in _build
graph = dispatch(sources, manager, stdout)
/home/miha/foss/mypy/mypy/build.py:2752: in dispatch
process_graph(graph, manager)
/home/miha/foss/mypy/mypy/build.py:3110: in process_graph
process_stale_scc(graph, scc, manager)
/home/miha/foss/mypy/mypy/build.py:3227: in process_stale_scc
manager.flush_errors(manager.errors.file_messages(graph[id].xpath), False)
/home/miha/foss/mypy/mypy/errors.py:707: in file_messages
return self.format_messages(self.error_info_map[path], source_lines)
/home/miha/foss/mypy/mypy/errors.py:680: in format_messages
source_line = source_lines[line - 1]
E IndexError: list index out of range
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| tp.line = newline | ||
| tp.column = newcolumn | ||
| for ta in getattr(tp, 'args', []): | ||
| replace_alias_location(ta, newline, newcolumn) |
There was a problem hiding this comment.
This might not find all component types (e.g. within callables). Also, we prefer to avoid getattr since it can't be type checked by mypy and mypyc generates slow code for it.
Can you instead define a subclass of TypeTraverserVisitor, and override at least visit_instance to update line/column info. You can use it to update all component type objects (of the desired types), and in a type-safe manner.
There was a problem hiding this comment.
@JukkaL I've updated the PR, please could you check again?
This comment has been minimized.
This comment has been minimized.
|
@JukkaL any chance to get the fix merged? |
JukkaL
left a comment
There was a problem hiding this comment.
A few additional minor things, otherwise looks good.
| new_tp.column = newcolumn | ||
| return new_tp | ||
| newtp = tp.accept(replacer) | ||
| newtp.accept(LocationSetter(newline, newcolumn)) |
There was a problem hiding this comment.
To make sure that we don't regress any existing use case, can you also set the line and column attributes of the return value of the visitor, in case line/column of non-Instance types is important.
|
|
||
|
|
||
| class LocationSetter(TypeTraverserVisitor): | ||
| def __init__(self, line: int, column: int) -> None: |
There was a problem hiding this comment.
Add a TODO comment along the lines of "Should we update locations of other Type subclasses?".
|
@JukkaL Thanks for your comments! I've updated PR as suggested. |
This comment has been minimized.
This comment has been minimized.
|
@JukkaL ping |
|
@oxidase There is now merge conflict, sorry, can't merge. Can you please rebase/merge? |
This comment has been minimized.
This comment has been minimized.
|
@JukkaL rebased to the current master |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
|
@JukkaL sorry, I can not merge in the repository due to
Please could you merge ^ PR? |
Description
Fixes #12678 by updating line and column not only in an alias type variable but also recursively in arguments.
The current develop output
The branch output
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)