Will `collections.abc.Set` also be deprecated in the future? like `typing.ByteString` and `collections.abc.ByteString` are deprecated

typing.Set is deprecated so will collections.abc.Set also be deprecated in the future? like typing.ByteString and collections.abc.ByteString are deprecated.

typing and collections are unrelated.

So, you mean collections.abc.Set won’t be deprecated, right?

But why won’t collections.abc.Set be deprecated while collections.abc.ByteString is deprecated?

And, we can use the built-in function set() as a type hint instead of collections.abc.Set.

Because mutable sets are in the Python forever. And we need for an ABC class to
reflect interfaces for sets.

Removal of collections.abc.ByteString is explained in docs:

ByteString was originally intended to be an abstract class that would serve as a supertype of both bytes and bytearray. However, since the ABC never had any methods, knowing that an object was an instance of ByteString never actually told you anything useful about the object. Other common buffer types such as memoryview were also never understood as subtypes of ByteString (either at runtime or by static type checkers).

See PEP 688 for more details.

You’re mixing up a bunch of closely related but still very much distinct concepts.

The classes in collections.abc are all abstract (that’s what the abc stands for) and thus can be implemented in a variety of ways by a variety of libraries, as long as they provide at least the same minimal interface and either directly inherit from the abc or is registered as a virtual subclass after the fact.

Type checkers go one step further and treat these classes as if they were a typing.Protocol, so any type that structurally matches e.g. collections.abc.Iterable will be accepted in a function that expects a collections.abc.Iterable, even if it doesn’t directly inherit from it.

So collections.abc.Set is to set and typing.Set, what collections.abc.Sequence is to list and typing.List. The actual equivalent to collections.abc.Set is typing.AbstractSet. The names are more confusing for sets than lists/dicts, because collections.abc predates typing and there isn’t really a better generic term for a set than Set.

2 Likes