-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle empty tuples consistently. Fixes #136.
It has now been documented (most recently in https://bugs.python.org/issue37814) that the correct way to annotate an empty tuple is `Tuple[()]`. The runtime behavior of such an annotation is perhaps slightly unexpected, in that `Tuple[()].__args__ == ((),)`, rather than `()` as you might expect it would be (to parallel e.g. `Tuple[int, str].__args__ == (int, str)`). On the other hand, this oddity is "useful" in that `Tuple.__args__ == ()`, so this allows us to distinguish at runtime un-subscripted `Tuple` (which I think must be interpreted as implicitly `Tuple[Any,...]` to parallel e.g. `List` being equivalent to `List[Any]`?) from `Tuple[()]`. This pull request makes MonkeyType's handling of tuple types consistent, in that `Tuple` will round-trip to `Tuple` and `Tuple[()]` to `Tuple[()]`, and in so doing fixes the crash with empty tuples in rewriters exposed in #136. A traced empty tuple will now be correctly represented in stubs as `Tuple[()]`.
- Loading branch information
Showing
5 changed files
with
18 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters