Literal type math
Open
Nobody has claimed this yet.
feature
topic-literal-types
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
I am working on feature where reveal_type(1 + 2) will reveal Literal[3].
Types that I want to support:
intstrbool
And these operations:
_SUPPORTED_LITERAL_OPERATIONS: Final = {
int: ('+', '-', '*', '//'), # `/` returns `float`
str: ('+',),
bool: ('and', 'or'),
}
So, True or False is revealed as Literal[True].
I will finish some test later today and send a PR in the morning.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the reveal_type examples and the proposed _SUPPORTED_LITERAL_OPERATIONS mapping. Trace how mypy evaluates expressions and represents literal types, then add coverage for the listed int, str, and bool operations. Done means the supported expressions reveal the expected Literal values while division remains float.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100