Make set.union and set.intersection convert a non-set self implicitly
Dec 19, 2023 ... Updated my original post with a better example for clarification of the use case. MegaIng (Cornelius Krupp) December 19, 2023, 3:59am 5.
Dec 19, 2023 ... Updated my original post with a better example for clarification of the use case. MegaIng (Cornelius Krupp) December 19, 2023, 3:59am 5.
Mar 8, 2024 ... Currently “file-like objects” in Python is perhaps the most extreme use case of a duck typing system. A function can take any object as a ...
Suppose I have some library code where I define a BaseType that is meant to be subclassed by users. Next, suppose I want to create an object that is both an instance of a user-defined type while also inheriting from a different library class.
Oct 23, 2025 · The important bit here is that the classes are not pre-defined, so I cannot just subclass them in code. Type checkers do barely (Pyright) or not all (mypy) understand dynamic type creation with type. Pyright can understand direct usage of type, but using it with generic functions is not understood by it.
Feb 10, 2023 ... I think my preferred resolution here is: Not type gets added some type alias like typing.StrictStr is added for str & ~typing.
Dec 23, 2023 ... else: # self is typed as "Nothing" here even though this code is perfectly reachable ... This is also impossible on methods of C-builtin types ...
Type intersection and negation might be useful concepts. That’s still to be established. 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.
Hey John @fonini has put it well clear…its all about data types. elements in the df are being stored as pandas series objects while a list a can have diferrent data types which I was playing about and found comparing a `"6"` to an int 6 with the list method will return true The `set` method con limits to unique intersection. nywy also found ...
Nov 23, 2023 ... This proposal is to add a type annotation to indicate that a true union of multiple types are returned. Currently, the union of multiple ...
I have a strong opinion that dictionaries in Python should have key-based set operations. I have a baseline implementation in my ubelt library call SetDict - ubelt.util_dict module — UBelt 1.3.2 documentation I spent a lot of time ...
Apr 13, 2022 · Why not use sets and the intersection operator (which is an operator, not a function, builtin or otherwise)? 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.
Oct 18, 2024 ... keys() not only is set-like, but actually implemented all set methods. My sample code to perform a dict - iterable operation: def dict_exclude(d ...
boom(x). def example(): b: B[int | str] = B(1, "this") indirection(b). Adding the detail that It’s the same type var in both parent and subclass closes the possibility that it’s just bad intersection narrowing that no type checker handles right now.
Why not use sets and the intersection operator (which is an operator, not a function, builtin or otherwise)? 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. ```python intersection = set (a) & set (b) ``` --- _ [View the full ...
Jul 17, 2024 ... ... code, and clearer expression of intent? How many Python users in 2024, intuitively expect the intersection of n sets to be included in the ...
**Author:**  [@blhsing](https://discuss.python.org/u/blhsing ...
Feb 8, 2025 ... A type intersection on the other hand is generally unordered, so it's not the same as defining a new protocol using two existing ones as ...