Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fast parser associates wrong column number with calls to member functions #2749

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ddfisher opened this issue Jan 23, 2017 · 5 comments
Closed
Labels
bug mypy got something wrong priority-1-normal topic-error-reporting How we report errors topic-parser

Comments

@ddfisher
Copy link
Collaborator

For example:

class A:
    def f(self, x): # type: (int) -> str
        pass
A().f('') # E:0: Argument 1 to "f" of "A" has incompatible type "str"; expected "int"
@ddfisher
Copy link
Collaborator Author

I don't think this is going to be easily fixable. Here's the ast for the expression A().f(''):

Expr(value=Call(
    func=Attribute(value=Call(func=Name(id='A', ctx=Load(), lineno=1, col_offset=0), args=[], keywords=[], lineno=1, col_offset=0),
                   attr='f', ctx=Load(), lineno=1, col_offset=0)
    , args=[Str(s='', lineno=1, col_offset=6)], keywords=[], lineno=1, col_offset=0),
    lineno=1, col_offset=0)]

Notice that all we know about f is that it's the string portion of an attribute lookup. It doesn't have any annotations (in the Python AST sense, i.e. line or col numbers) itself, aside from what's associated with the attribute lookup as a whole. Unfortunately, the column number associated with the attribute lookup is the first column of the value (in this case, A()), which starts in the 0th column.

@gvanrossum
Copy link
Member

So I'm guessing this would require an update to typed_ast. Oh well. Low priority is fine.

@ddfisher
Copy link
Collaborator Author

And what the fix would look like is not obvious (at least not to me), unfortunately.

@ilevkivskyi
Copy link
Member

(Raising priority in view of planned editor integration.)

@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 3, 2022

I'm closing this issue: it doesn't appear to be a problem when mypy is run on 3.8+, as mypy uses the stdlib ast module on these newer versions of Python.

It seems unlikely to me that typed_ast will be updated to fix this issue, given that typed_ast is only really useful on Python <=3.7.

@AlexWaygood AlexWaygood added bug mypy got something wrong topic-error-reporting How we report errors labels Apr 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal topic-error-reporting How we report errors topic-parser
Projects
None yet
Development

No branches or pull requests

4 participants