Comments (12)
It would be great to use str | None
instead of Optional[]
. @tiangolo: Any plans to implement this to support >= Python3.11?
from typer.
Switching from
str | None = None
toOptional[str] = None
worked for me.That is a pretty good workaround, but for me it means that I have to configure my linters one way for modules that use typer and another way for the rest of the code.
pyupgrade will respect type aliases, as will typer. It's unwieldy, but this means you can do the following without having to configure pyupgrade to keep runtime types:
OptionalStr = Optional[str]
main(
foo: OptionalStr = typer.Argument(None),
) -> None:
...
from typer.
For me, I'd rather use Optional[str]
than making an alias named OptionalStr
(that someone then has to look up to know exactly how it was defined).
I think the idea here is that we ideally want to use str | None
as is the new, preferred style, that pyupgrade/Ruff also lint for.
from typer.
For me, I'd rather use
Optional[str]
than making an alias namedOptionalStr
(that someone then has to look up to know exactly how it was defined).I think the idea here is that we ideally want to use
str | None
as is the new, preferred style, that pyupgrade/Ruff also lint for.
Agree, for now I've just disabled linting in that specific line, in Ruff you can do it with #noqa: UP007
from typer.
I'm having the same issue. Using Union[type1, type2]
with from typing import Union
leads to the same error.
from typer.
@tiangolo, Any updates on this feature?
from typer.
Related to
from typer.
Hi and thanks a lot for this great library!
I've run into this issue as well. May someone provide some guidance on what should be fixed,
in case someone would like to contribute to solve it?
from typer.
I have the same issue with Python 3.10. Any advisory on how to fix this?
from typer.
Switching from str | None = None
to Optional[str] = None
worked for me.
from typer.
Switching from
str | None = None
toOptional[str] = None
worked for me.
That is a pretty good workaround, but for me it means that I have to configure my linters one way for modules that use typer and another way for the rest of the code.
from typer.
I am stuck between Typer not supporting the new python syntax with |None=None
and pyupgrade refusing to add an option to skip code for a specific line. I guess I'll try this solution.....
Switching from
str | None = None
toOptional[str] = None
worked for me.That is a pretty good workaround, but for me it means that I have to configure my linters one way for modules that use typer and another way for the rest of the code.
pyupgrade will respect type aliases, as will typer. It's unwieldy, but this means you can do the following without having to configure pyupgrade to keep runtime types:
OptionalStr = Optional[str] main( foo: OptionalStr = typer.Argument(None), ) -> None: ...
from typer.
Related Issues (20)
- How do I pass the None value explicitly? HOT 2
- Documentation is misleading. new `typer.run` behavior HOT 2
- See if rich 13.x is compatible HOT 4
- unlimited argument for an option with comma spliter HOT 1
- TAB completion is giving local directory files where command is called. HOT 2
- Support for bytes in Options and Arguments HOT 2
- Is it possible to include a Prolog in `--help` HOT 2
- Get the typer output with html format to provide it to termynal HOT 5
- how to use typer on class method __init__ with self argument, got this error: Error: Missing argument 'SELF'. HOT 2
- Support for localization of messages HOT 1
- Auto-completion when application works in 2 modes (GUI, CLI) HOT 1
- DOC: Documentation of passing multiple values in "option" vs "argument" isn't sufficiently explicit HOT 1
- SIGINT from docker is ignored HOT 4
- 🚀 Roadmap HOT 2
- Source distribution of 0.11.0 is missing the `docs_src` folder HOT 1
- 🐛 Upgrading from `typer<0.12.0` to `typer==0.12.0` breaks the install by partially removing the package/module files HOT 4
- Rich markup in generated Markdown docs HOT 1
- Add CI configs to run tests on Windows and MacOS
- Rich markup in Zsh completion help lines
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typer.