-
-
Notifications
You must be signed in to change notification settings - Fork 672
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
[BUG] envvar
incorrect type: click accepts Sequence[str]
#283
Comments
Can you elaborate on |
Types are for more than intent. |
I think what @kkirsche meant was that a string for x in "abcd":
print(x) would print: a
b
c
d also from collections import Sequence, Iterable
print(isinstance("abc", Collection))
print(isinstance("abc", Sequence)) would both be |
Are we drawing conclusions that don't follow? import collections.abc as CA
def normalize(input: CA.Iterable[str]) -> tuple[str, ...]:
return (input,) if isinstance(input, str) else tuple(input) Nothing in the general type annotation forces the implementation to iterate over each character in a string: the implementation is free to do anything that meets type requirements. Yes, Now inspect the implementation. |
I think we have very different definitions on the purpose of types, which is fine. It sounds as though you operate from the pure type perspective, meaning the purpose of types is to document what a function could operate on, influenced from languages like Haskell. This is perfectly valid, it simply differs from what I’ve encountered and find in code of my peers. In practice, I find that teams I’ve worked with use types and type checking as extended documentation. Abstract typing can be valuable, but if I want the user to pass a list, I document a list even though it could operate on other types. Both can be valid, but they aren’t really compatible philosophies. Agree to disagree on their purpose. I appreciate you taking the time to explain. |
python/typing#256: the type hint Documentation: this is an admirable goal that I fully support. envvar: Optional[Union[str, Sequence[str]]] = None seems clear in documentation without placing contrived, counterproductive limitations on implementers using this library. Notice this discussion only exists because unlike documentation, type hints can restrict programs from validating. If someone is going to claim typing by subjective "intent" is valid, and that "intent" unnecessarily classifies valid Python code as invalid to static type-checkers, then they better be ready to justify their intent. I'm probably not the only programmer who wants to get the most out of type hints if they're going to bother using them. |
envvar
incorrect type: click accepts Sequence[str]
https://github.com/tiangolo/typer/blob/c3a4c72a4f1a18b7f16addb508862ec63411fa63/typer/params.py#L14
Why
List
?Do we expect to mutate the data?
I'd expect immutable types allowed.
Maybe this should be generalized to an abstract interface such as
Sequence
orIterable
.In general, any overspecialized parameters should be generalized.
The text was updated successfully, but these errors were encountered: