Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Start propagating end columns/lines through fortype-arg errors#18533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ilevkivskyi merged 2 commits intopython:masterfromA5rocks:end-columns-are-good-1
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletionsmypy/fastparse.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2052,13 +2052,16 @@ def visit_Subscript(self, n: ast3.Subscript) -> Type:

value = self.visit(n.value)
if isinstance(value, UnboundType) and not value.args:
return UnboundType(
result = UnboundType(
value.name,
params,
line=self.line,
column=value.column,
empty_tuple_index=empty_tuple_index,
)
result.end_column = getattr(n, "end_col_offset", None)
result.end_line = getattr(n, "end_lineno", None)
return result
else:
return self.invalid_type(n)

Expand DownExpand Up@@ -2092,7 +2095,7 @@ def visit_Attribute(self, n: Attribute) -> Type:
before_dot = self.visit(n.value)

if isinstance(before_dot, UnboundType) and not before_dot.args:
return UnboundType(f"{before_dot.name}.{n.attr}", line=self.line)
return UnboundType(f"{before_dot.name}.{n.attr}", line=self.line, column=n.col_offset)
else:
return self.invalid_type(n)

Expand Down
10 changes: 9 additions & 1 deletionmypy/semanal.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7219,7 +7219,15 @@ def fail(
if code is None:
code = msg.code
msg = msg.value
self.errors.report(ctx.line, ctx.column, msg, blocker=blocker, code=code)
self.errors.report(
ctx.line,
ctx.column,
msg,
blocker=blocker,
code=code,
end_line=ctx.end_line,
end_column=ctx.end_column,
)

def note(self, msg: str, ctx: Context, code: ErrorCode | None = None) -> None:
if not self.in_checked_function():
Expand Down
4 changes: 4 additions & 0 deletionsmypy/typeanal.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -862,6 +862,8 @@ def analyze_type_with_type_info(
ctx.line,
ctx.column,
)
instance.end_line = ctx.end_line
instance.end_column = ctx.end_column
if len(info.type_vars) == 1 and info.has_param_spec_type:
instance.args = tuple(self.pack_paramspec_args(instance.args))

Expand DownExpand Up@@ -2204,6 +2206,8 @@ def instantiate_type_alias(
tp = Instance(node.target.type, args)
tp.line = ctx.line
tp.column = ctx.column
tp.end_line = ctx.end_line
tp.end_column = ctx.end_column
return tp
if node.tvar_tuple_index is None:
if any(isinstance(a, UnpackType) for a in args):
Expand Down
14 changes: 14 additions & 0 deletionstest-data/unit/check-columns.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -408,3 +408,17 @@ x[0]
main:2:10:2:17: error: Incompatible types in assignment (expression has type "str", variable has type "int")
main:6:3:7:1: error: Argument 1 to "f" has incompatible type "int"; expected "str"
main:8:1:8:4: error: Value of type "int" is not indexable

[case testEndColumnsWithTooManyTypeVars]
# flags: --pretty
import typing

x1: typing.List[typing.List[int, int]]
x2: list[list[int, int]]
[out]
main:4:17: error: "list" expects 1 type argument, but 2 given
x1: typing.List[typing.List[int, int]]
^~~~~~~~~~~~~~~~~~~~~
main:5:10: error: "list" expects 1 type argument, but 2 given
x2: list[list[int, int]]
^~~~~~~~~~~~~~
4 changes: 2 additions & 2 deletionstest-data/unit/check-parameter-specification.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1345,8 +1345,8 @@ from typing import Callable, ParamSpec
P1 = ParamSpec('P1')
P2 = ParamSpec('P2')

def f0(f: Callable[P1, int], *args: P1.args, **kwargs: P2.kwargs): ... # E: ParamSpec"P2" is unbound \
# E: ParamSpecmust have "*args" typed as "P1.args" and "**kwargs" typed as "P1.kwargs"
def f0(f: Callable[P1, int], *args: P1.args, **kwargs: P2.kwargs): ... # E: ParamSpecmust have "*args" typed as "P1.args" and "**kwargs" typed as "P1.kwargs" \
# E: ParamSpec"P2" is unbound

def f1(*args: P1.args): ... # E: ParamSpec "P1" is unbound
def f2(**kwargs: P1.kwargs): ... # E: ParamSpec "P1" is unbound
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp