Skip to content
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

Don't add strange fictional parameters to the signature of NamedTuple._make() #15578

Merged
merged 1 commit into from Jul 3, 2023

Conversation

AlexWaygood
Copy link
Member

It appears that mypy currently synthesises two fictional parameters for the NamedTuple classmethod _make(): new and len. I'm not sure why we do this? They've never existed at runtime, and all tests pass if we remove them (except for two that need to be changed slightly, due to the output of reveal_type(namedtuple_cls._make) changing).

It looks like we've been adding these parameters since support for _make() was first added in 2016: #1810. I can't find any reference in that PR thread about why we add these parameters, however.

This PR proposes that we stop adding these parameters, which makes the output of reveal_type(namedtuple_class._make) much more accurate :)

@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2023

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@hauntsaninja hauntsaninja merged commit 49d95cf into python:master Jul 3, 2023
18 checks passed
@hauntsaninja
Copy link
Collaborator

Interesting!

@AlexWaygood AlexWaygood deleted the nmdtpl-weird branch July 3, 2023 19:47
@AlexWaygood
Copy link
Member Author

Interesting!

Indeed!!

@TeamSpen210
Copy link
Contributor

Looks like these did actually exist, up until Py3.7. But they were just private early bindings for tuple.__new__ and len, not really intended as public API.

@AlexWaygood
Copy link
Member Author

Looks like these did actually exist, up until Py3.7. But they were just private early bindings for tuple.__new__ and len, not really intended as public API.

Ahh, thank you! That makes a lot more sense now :) I checked the docs all the way back to 2.6, but only checked the source code and in the REPL on a few recent Python versions.

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

Successfully merging this pull request may close these issues.

None yet

3 participants