8000 Bare `Tuple` should mean `Tuple[Any, ...]`. by gvanrossum · Pull Request #2185 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Bare Tuple should mean Tuple[Any, ...]. #2185

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

Merged
merged 3 commits into from
Sep 27, 2016
Merged

Bare Tuple should mean Tuple[Any, ...]. #2185

merged 3 commits into from
Sep 27, 2016

Conversation

gvanrossum
Copy link
Member

Fix #2184. (See also python/typing#284.)

def f(a: Tuple) -> None: pass
f(())
f((1,))
f(('', ''))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call with a non-tuple argument such as an int.

@gvanrossum
Copy link
Member Author

Ouch. I just realized that I broke the behavior of Tuple[()]. I added a test for that but didn't finish that thought.

@gvanrossum
Copy link
Member Author

@JukkaL Another look? I added the test with int you requested, and fixed the issue I introduced with Tuple[()] -- that was a little awkward since the information about whet 8000 her the original code was Tuple or Tuple[()] was lost by the time it reached typeanal.py.

I also looked into the difference with the next block and decided to leave that alone (although reducing it to self.builtin_type('builtins.tuple', [t.args[0].accept(self)]) made all tests pass, I decided to give it the benefit of the doubt, maybe the line number is important after all).

@elazarg
Copy link
Contributor
elazarg commented Sep 27, 2016

If I understand correctly, this flag may be useful in order to write Union[] as a synonym for UninhabitedType (i.e. NoReturn) , while still allowing Union to be Union[Any] (which is actually Any).

@gvanrossum
Copy link
Member Author

Sorry, Union[](like Tuple[]) is invalid syntax. We use Tuple[()] as an
escape, but Union[()] would be too ugly for such a purpose.

from typing import Tuple
def f(a: Tuple[()]) -> None: pass
f(())
f((1,)) # E: Argument 1 to "f" has incompatible type "Tuple[int]"; expected "Tuple[]"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe update the output 8000 of an empty tuple to be Tuple[()] instead of Tuple[]?

@JukkaL
Copy link
Collaborator
JukkaL commented Sep 27, 2016

Other than the comment above, this looks good to me.

@gvanrossum
Copy link
Member Author

About Tuple[] vs. Tuple[()] in output... I have the patch for that ready,
but I'm not sure I like it. I had to change some other tests that had
Tuple[] in their output, and somehow I have a feeling that for a user,
seeing Tuple[] is more indicative of "the type of an empty tuple" than
Tuple[()], which only works for obscure reasons. So I think I'd like to
leave this for a later time.

@gvanrossum gvanrossum merged commit 0d2c594 into master Sep 27, 2016
@JukkaL
Copy link
Collaborator
JukkaL commented Sep 27, 2016

OK, sounds reasonable Tuple[()] really isn't the most intuitive thing ever.

@gvanrossum gvanrossum deleted the bareTuple branch September 27, 2016 17:03
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.

3 participants
0