On Wed, Aug 26, 2020 at 10:10 PM Christopher Barker <pythonchb@gmail.com> wrote:
Honestly, I haven't delved into type checking much, so maybe I'm making this up, but what if you write a function that is type hinted to take a Mapping, and uses | or |=, and all the test code uses a built in dict, and all seems to be well.

This made me curious so I did an experiment, but with Set because I couldn't be bothered to worry about Python versions. This code:

```
import typing
import collections
import builtins

def foo(t: typing.Set, c: collections.Set, b: builtins.set):
    print(t + t)
    print(t | t)
    print(t.union(t))

    print(c + c)
    print(c | c)
    print(c.union(c))
   
    print(b + b)
    print(b | b)
    print(b.union(b))
```

complains about `+` (as it should) and `c.union` in both PyCharm and mypy, and nothing else. So typing.Set is based on the builtin and not the ABC. If you want to support any subclass of collections.Set, your type hint needs to be collections.Set. Using typing.Set will fail to show warnings when you use a builtin only method, and will show warnings when you try to assign an ABC set (e.g. I get a warning with `foo(t=<instance of collections.abc.Set>)`. The problem then is that `collections.abc.Set[int]` doesn't work, i.e. you need to use typing.Set if you want generics.