I did a a cursory investigation using GitHub search and also looked at
a big internal codebase, and a significant fraction of callsites used
a dict type instead of a TypedDict or a dict literal.
It seems that it's a common use case to store the config within an
attribute. For example, something like this:
```
CONFIG = {
...
}
...
logging.config.dictConfig(CONFIG)
```
Another use case that was not properly supported is reading the
config from a file, and the config is given `dict[str, Any]` as
the type.
Mypy can still do some type checking of the argument if called
with a dict literal, so I feel this is a reasonable compromise
between type checking strictness and usability.
pyanalyze checks parameter names for protocols strictly, so `float` didn't match these protocols.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* get rid of --ignore-missing-stub
* update allowlists based on github actions logs, with script
import re
platforms = ["linux", "win32", "darwin"]
versions = ["py36", "py37", "py38", "py39", "py310"]
entries_by_pv = {}
for p in platforms:
for v in versions:
p_name = {"linux": "ubuntu", "darwin": "macos", "win32": "windows"}[p]
v_name = "3." + v.replace("py3", "")
if v_name == "3.9":
v_name = "3.9.7"
entries = set()
with open(f"la/Check stdlib with stubtest ({p_name}-latest, {v_name})/6_Run stubtest.txt") as file:
for line in file:
m = re.search(r"error: (.*) is not present in stub$", line.strip())
if m:
entries.add(m.group(1))
entries_by_pv[p, v] = entries
def remove_intersection(sets):
sets = list(sets)
result = set(sets[0])
for s in sets[1:]:
result &= s
for s in sets:
for r in result:
s.remove(r)
return result
common_to_all = remove_intersection(entries_by_pv.values())
common_to_version = {}
for v in versions:
common_to_version[v] = remove_intersection([
entries
for (p, v2), entries in entries_by_pv.items()
if v == v2
])
common_to_platform = {}
for p in platforms:
common_to_platform[p] = remove_intersection([
entries
for (p2, v), entries in entries_by_pv.items()
if p == p2
])
def write(fname, entries):
with open(f"tests/stubtest_allowlists/{fname}.txt", "a") as file:
file.write("\n# Exists at runtime, but missing from stubs\n")
for i in sorted(entries):
file.write(i + "\n")
write("py3_common", common_to_all)
for v, entries in common_to_version.items():
write(v, entries)
for p, entries in common_to_platform.items():
write(p, entries)
for (p, v), entries in entries_by_pv.items():
write(p + "-" + v, entries)
* Manually combine __main__ attributes into a single entry
* move and comment entries manually
At runtime it only uses positional parameters.
I think this works fortuitously in mypy and pyright because mypy ignores parameter names in protocols and pyright has a bug that allows passing positional-only to pos-or-keyword params (microsoft/pyright#2652) and the parameter to `io.TextIO.write` happens to be `__s`.
These functions will fail at runtime if `other` is not either a `list` or a `UserList`. The elements within `other` must also be of the same type as the elements within `self`, or the comparison will fail.