Replies: 7 comments
-
|
Can you elaborate on |
Beta Was this translation helpful? Give feedback.
-
|
Types are for more than intent. |
Beta Was this translation helpful? Give feedback.
-
|
I think what @kkirsche meant was that a string for x in "abcd":
print(x)would print: a
b
c
dalso from collections import Sequence, Iterable
print(isinstance("abc", Collection))
print(isinstance("abc", Sequence))would both be |
Beta Was this translation helpful? Give feedback.
-
|
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. |
Beta Was this translation helpful? Give feedback.
-
|
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. |
Beta Was this translation helpful? Give feedback.
-
|
python/typing#256: the type hint Documentation: this is an admirable goal that I fully support. envvar: Optional[Union[str, Sequence[str]]] = Noneseems 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. |
Beta Was this translation helpful? Give feedback.
-
|
Maybe my last comment was too verbose, and a picture is needed. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
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
SequenceorIterable.In general, any overspecialized parameters should be generalized.
Beta Was this translation helpful? Give feedback.
All reactions