Hi Paul, all, Am 15.10.21 um 18:49 schrieb Paul Moore: > Mypy correctly rejects this: > [...]
interesting. Thanks for trying. > If typeguard doesn't, maybe you need to raise that as a bug against > that project? This is kind of contradicting the design of typeguard. It works on a call level checking arguments and return values for the most part. Typeguard does not provide any form of type inference like mypy does. >From this perspective, typeguard would need to guard `dict.__init__`, `dict.__setitem__`, `dict.update` and friends directly, essentially requiring a subclass of `dict` of some sort. However, typeguard does have a special function to perform type checks on objects, e.g. `check_type('variablename', [1234], List[int])` Ignoring typeguard, my suggestion still stands, although slightly changed: Annotating a dictionary as described earlier in such a way that type inference is not required OR in such a way that run-time checkers have a chance to work more easily - if this makes any sense at all? Best regards, Sebastian _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MNTNS2H27GKQP7SJOYCVGL4ZFA73SLPA/ Code of Conduct: http://python.org/psf/codeofconduct/