Functions in class bodies that aren't methods - Python Discussions
Dec 23, 2023 ... A recent thread about the proposed extension of set methods raised a question I often wondered about, and which I find interesting because ...
Dec 23, 2023 ... A recent thread about the proposed extension of set methods raised a question I often wondered about, and which I find interesting because ...
# Code is an illustrative example only, more practical examples follow def get_value() -> int | Raises[ValueError]: if random.random() < 0.5Note that I am not proposing that Python add a comprehensive checked exception system similar to Java.
Mar 23, 2024 ... What happens if I use your example as some_library add something like this to my code: ... Because Python has a rich set of features ...
I’ve been using Python since 1.4 and was somewhat surprised to see this typo working: assert {'1','2'}.intersection('12') I would have expected it to give me a syntax error, claiming that this is required: assert {'1','2'}.intersection(set('12'...
I think, at least for type intersections it’s well established. Aside from what is discussed here, a common use-case is intersecting Protocols. Many languages support intersection types.There are many example problems in the type intersection issue on MyPy. Randolf Scholz
For example, you might want to state that an argument must be an Iterable and a Container (for example, it could be a Set, a Mapping or a Sequence). It would be nice if this could be spelled like this: ``` def assertIn(item: T, thing: Intersection[Iterable[T], Container[T]]) -> None...
A set is a far more appropriate and efficient data structure for this problem…lists are for things that have order and contain multiple identical, potentially non-hashable elements, none of which are desirable here. intersection = set(a) & set(b).