Skip to content

Fix namedtuple discrepancies #2090

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
2 of 5 tasks
elazarg opened this issue Sep 3, 2016 · 11 comments
Closed
2 of 5 tasks

Fix namedtuple discrepancies #2090

elazarg opened this issue Sep 3, 2016 · 11 comments

Comments

@elazarg
Copy link
Contributor

elazarg commented Sep 3, 2016

@dlinnemeyer
Copy link

I'm working on trying out NamedTuple from typing with mypy, and I ran into an error claiming my tuple has no attribute "_replace" when I try to call _replace.

Is this what you're talking about here, or am I running into a different problem?

@elazarg
Copy link
Contributor Author

elazarg commented Sep 22, 2016

What version of mypy do you use? This sounds like an old bug that should have been fixed. Can you post an example code?

@dlinnemeyer
Copy link

0.4.4. I'll work on some example code quickly.

@dlinnemeyer
Copy link

from typing import NamedTuple

Foo = NamedTuple('Foo', [
    ('x', int),
    ('y', str)
])

def do_something(foo: Foo) -> Foo:
    return foo._replace(x=7)

I'm getting this error:

test.py: note: In function "do_something":
test.py:9: error: "Foo" has no attribute "_replace"

@gvanrossum
Copy link
Member

gvanrossum commented Sep 22, 2016 via email

@elazarg
Copy link
Contributor Author

elazarg commented Sep 22, 2016

No it was fixed but not released yet.

@gvanrossum
Copy link
Member

Our policy is to close bugs when the fix lands in the repo. So if this issue is fixed in the repo it should be closed now. (As the originator you should be able to.)

@dlinnemeyer
Copy link

You were right. Installing directly from git doesn't give any errors.

@elazarg
Copy link
Contributor Author

elazarg commented Sep 22, 2016

@gvanrossum please don't close this issue. It is about other problems, not yet solved.

@gvanrossum
Copy link
Member

Sorry!

@gvanrossum gvanrossum reopened this Sep 22, 2016
gvanrossum pushed a commit that referenced this issue Nov 7, 2016
gvanrossum pushed a commit that referenced this issue Nov 13, 2016
(Reopening #2408 after the revert #2414. This fixes parts of #2090)
This PR does three things:

    Fix the handling of TupleType (pass original_type recursively)
    Fix the handling of TypeType (avoid ad-hoc buggy special casing)
    Make NamedTuple's _replace() and _make() return selftype, serving as test case for (1) and (2)

As a consequence of (1), some error messages are changed, as exemplified in check-isinstance.test. I think it's better now, but if it isn't, perhaps we should separate original_type and report_type as discussed in #2193.
@emmatyping
Copy link
Member

namedtuple is no longer an experimental mypy concept, I think this can be closed. Any work left belongs in python/typing or CPython :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants