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

✨ Support typing.Literal in Python 3.8+ #429

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

blackary
Copy link

Copied PR #174 from someone who deleted their account because I think it's worth reopening this PR and adding this functionality to typer.

Original PR message:

Support for typing.Literal for creating choices, without actually having to create Enum types. Requires Python 3.8, referenced in #76. I ran tests again 3.6 without problems, so I think the version check if working OK.

@github-actions
Copy link

📝 Docs preview for commit d83f792 at: https://62d04b8528f3e0240fbc7885--typertiangolo.netlify.app

@codecov
Copy link

codecov bot commented Jul 14, 2022

Codecov Report

Attention: Patch coverage is 43.75000% with 18 lines in your changes missing coverage. Please review.

Project coverage is 99.69%. Comparing base (1e43c6b) to head (d83f792).
Report is 237 commits behind head on master.

Current head d83f792 differs from pull request most recent head a771189

Please upload reports for the commit a771189 to get more accurate results.

Files Patch % Lines
...test_parameter_types/test_enum/test_tutorial003.py 44.82% 16 Missing ⚠️
typer/main.py 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #429      +/-   ##
==========================================
+ Coverage   96.24%   99.69%   +3.44%     
==========================================
  Files         280      286       +6     
  Lines        5942     6456     +514     
==========================================
+ Hits         5719     6436     +717     
+ Misses        223       20     -203     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link

📝 Docs preview for commit 7a3466d at: https://639cea33a12b8e0af09de2a5--typertiangolo.netlify.app

@github-actions
Copy link

📝 Docs preview for commit 1e261e6 at: https://63a3728fbc88656dcfeedf1c--typertiangolo.netlify.app

@prompteus
Copy link

Any updates on merging this? @tiangolo

@hoishing
Copy link

hoishing commented Feb 4, 2023

Upvote for this PR, as using Literal is more succinct then using enum.

Copy link

@atmartinez atmartinez left a comment

Choose a reason for hiding this comment

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

There is the possibility to import Literal from typing_extensions to allow this to work for 3.6 (since Typer still says it support it despite being EOL) and 3.7 as well. This may be a moot consideration soon though since 3.7 goes EOL in June 2023 as well if there are any plans to drop unsupported Python versions at some point.

This may require adding a specific dependency for typing_extensions, but it's currently being installed by another dep regardless from some of the CI runs I checked for 3.6+ 4.1-4.4 depending on the Python version.

Example implementation for using typing_extensions

@svlandeg svlandeg added feature New feature, enhancement or request types Type hints and type checking p3 labels Feb 29, 2024
@svlandeg svlandeg marked this pull request as draft June 3, 2024 12:45
Copy link

github-actions bot commented Jun 3, 2024

📝 Docs preview for commit d4cd3c3 at: https://6e1d3ac2.typertiangolo.pages.dev

Copy link

github-actions bot commented Jun 3, 2024

📝 Docs preview for commit c7dd353 at: https://89793d8d.typertiangolo.pages.dev

Copy link

github-actions bot commented Jun 3, 2024

📝 Docs preview for commit 01d8013 at: https://1d46deb9.typertiangolo.pages.dev

Copy link

github-actions bot commented Jun 3, 2024

📝 Docs preview for commit 6065329 at: https://85835217.typertiangolo.pages.dev

Copy link

github-actions bot commented Jun 3, 2024

📝 Docs preview for commit 3b9034b at: https://a0405a66.typertiangolo.pages.dev

@svlandeg
Copy link
Member

svlandeg commented Jun 3, 2024

@svlandeg svlandeg marked this pull request as ready for review June 3, 2024 14:20
@svlandeg
Copy link
Member

svlandeg commented Jun 3, 2024

Thanks for this PR @blackary! I've taken the liberty to update this PR with the latest from master. I also added some improvements using new functionality from _typing.py, taking inspiration from the similar PR #669. This PR and that one now both cover largely the same functionality. I would personally merge this one and close the other, but will leave the final decision with Tiangolo as usual 😇

@svlandeg svlandeg linked an issue Jun 3, 2024 that may be closed by this pull request
@blackary
Copy link
Author

blackary commented Jun 3, 2024

Thanks @svlandeg!

Copy link

📝 Docs preview for commit a771189 at: https://4a31fc21.typertiangolo.pages.dev

@k4black
Copy link

k4black commented Jul 4, 2024

Gently ping @tiangolo

@svlandeg
Copy link
Member

svlandeg commented Aug 9, 2024

Hi all,

There's no need for pinging individual maintainers - this PR is on our internal board and will be reviewed further when Tiangolo has time. All the additional pings make our Github notifications difficult to use and only costs more time 😉 Thanks for your patience!

Copy link

github-actions bot commented Aug 9, 2024

Copy link

Copy link

@svlandeg svlandeg changed the title ✨ Support typing.Literal in Python 3.8+ ✨ Support typing.Literal in Python 3.8+ Aug 26, 2024
Copy link

github-actions bot commented Sep 2, 2024

Copy link

github-actions bot commented Sep 2, 2024

@svlandeg
Copy link
Member

svlandeg commented Sep 2, 2024

Currently, the CI is failing with

Run ls -la coverage
ls: cannot access 'coverage': No such file or directory
Error: Process completed with exit code 2.

I'm pretty confused why this happens here though 🤔

Update: this looks to be an issue separate from this PR - we're looking into it!

Update 2: this should be fixed by #967

Copy link

github-actions bot commented Sep 2, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature, enhancement or request p3 types Type hints and type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Literal type support
9 participants