-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Refactor NamedTuple to put it in a stub #3102
Comments
In theory I would love to get rid of the special-casing for NamedTuple, if possible. (Then again I'd also love to get rid of the special-casing for TypedDict.) In practice I'm not sure that it's worth anybody's effort -- and if you're volunteering, don't forget the poor reviewers who would have to spend time reviewing your PR, sometimes the review takes more effort than writing the code. It would certainly at this point be a large and subtle change to mypy, so beware of taking on too much (especially if you haven't dug around in the mypy code before). |
I think that making the type system general enough to represent named tuples or typed dicts without special casing is going to be a very big task and quite possible not even desirable. The named tuple special casing is ugly, yes, but it's mostly implemented already and the code isn't terribly difficult to understand or maintain. I don't really care too much about a bit of ugly code within mypy internals as long as the ugliness is contained within a specific part of the codebase, it's not hard to understand and there's not too much of that. In this case, my preferred improvement would be to move the named tuple specific code to another file that would be called from the semantic analyzer. I also wrote something about generic tuples elsewhere (#685 (comment)). |
I agree it's not obvious whether making NamedTuple completely without special casing is worth the effort, but at least parts of it are, if not today, then tomorrow. Specifically the following seems useful in general:
Each of these can reduce the special-casing inside mypy and allow other libraries to implement similar types of their own without writing plugins. Again, I do not claim it should be top-priority of anyone. I am thinking about it from time to time and if I'll find a way to implement some parts without huge changes I will give it a shot. I do not propose doing anything big in one go. I think TypedDict should be special-cased. I think it can be the core of +1 on moving the NamedTuple/TypedDict/NewType parts to a dedicated module; I did something like that in the abandoned |
Based on @elazarg comment on gitter:
This was in response to my question about how to make
NamedTuple
support generics (#2875, #685, #1682).I can try to do that, but wanted to get feedback first.
Also, @JelleZijlstra:
The text was updated successfully, but these errors were encountered: