Commit Graph

3619 Commits

Author SHA1 Message Date
Alex Waygood
f3026dc3ab Improve enum.StrEnum (#6580)
A `StrEnum` can only have strings as values.
2021-12-13 17:59:31 +01:00
Jukka Lehtosalo
78806f5402 Use AbstractSet instead of set in random and inspect (#6574) 2021-12-13 17:26:28 +01:00
Alex Waygood
cc054efa79 Make name and value read-only for Enums, part II (#6578) 2021-12-13 17:00:28 +01:00
Jukka Lehtosalo
8a5d91ca37 Relax signature of logging.config.loadConfig (#6577)
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.
2021-12-13 07:31:15 -08:00
Alex Waygood
0f2e87e42a Make name and value read-only for Enums (#6576) 2021-12-13 16:08:49 +01:00
Alex Waygood
c3cd88ba91 Add EnumMeta.__new__ & EnumMeta.__call__ (#6572) 2021-12-13 12:33:54 +01:00
Jelle Zijlstra
88c8a5829e More precise return type for sum() (#6573)
It returns 0 on an empty iterable, and that's the only int it can return for arbitrary iterables.
2021-12-12 16:58:01 -08:00
Alex Waygood
a774e52fae Correct builtins.help (#6571) 2021-12-12 17:09:34 +02:00
Nikita Sobolev
b1f0271da6 Add EnumType to enum.pyi on Python 3.11 (#6568) 2021-12-11 19:13:32 +02:00
Shantanu
f9cedff5af ast: allow non-literal strings (#6566)
Co-authored-by: hauntsaninja <>
2021-12-10 21:48:46 -08:00
Jelle Zijlstra
943dc5f61d More permissive type for random.choice and related functions (#6562) 2021-12-10 19:50:02 +01:00
Pavel Karateev
739a052c40 Add more ast.parse() mode overrides (#6522)
eval -> Expression
func_type -> FunctionType
single -> Interactive

We need (simplified) to cover all cases in Python >= 3.8

- 1 case: parse(filename: str = ...)
- 4 cases: parse(filename: str, mode: Literal[...])
- 4 cases: parse(*, mode: Literal[...])
2021-12-10 09:22:23 -08:00
Alex Waygood
84fd495b65 Update importlib to reflect recent changes (#6557) 2021-12-10 14:32:55 +01:00
Jelle Zijlstra
7d4d58925a typing: update comments (#6558) 2021-12-09 21:15:27 -08:00
Alex Waygood
65f0e8b770 Improve pydoc stubs (#6554) 2021-12-09 14:28:35 +01:00
Alex Waygood
1718b77a1a Remove redundant method redefinitions in builtins (#6545) 2021-12-08 16:29:07 +01:00
Alex Waygood
ba2bfae4f9 Add xml.etree.ElementInclude.LimitedRecursiveIncludeError (#6547) 2021-12-08 16:27:56 +01:00
Alex Waygood
1fdd7e40af Add missing objects to xml.etree.ElementTree (#6540)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
2021-12-08 15:02:54 +02:00
Alex Waygood
1d5857e1e0 Add xml.dom.InvalidCharacterErr (#6538)
* Update __init__.pyi

* Update py3_common.txt
2021-12-07 13:32:24 -08:00
Alex Waygood
3aab6f1348 Add missing properties to xml.dom.minidom (#6526) 2021-12-07 18:40:33 +02:00
Akuli
7155bdae63 Re-export more os functions in posix, tweak availability on linux (#6529) 2021-12-07 16:10:41 +01:00
Akuli
44f71867c7 add tkinter.EventType aliases (#6516) 2021-12-07 15:10:39 +02:00
Alex Waygood
a69ef8f1ad Clean up threading.pyi (#6525)
- Adds comments to aliases in the `threading` module to indicate that they're deprecated.
- Adds two missing aliases, for consistency.
- Closes #6494
2021-12-06 16:21:27 -08:00
Jelle Zijlstra
72ee95bc0b operator: make Protocol parameters positional-only (#6519)
pyanalyze checks parameter names for protocols strictly, so `float` didn't match these protocols.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2021-12-06 10:49:24 -08:00
Alex Waygood
6b2218846c Add stub for xml.dom.expatbuilder (#6517)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
2021-12-06 20:39:01 +02:00
Akuli
af85e18bec tkinter Pack,Grid,Place: delete commented-out aliases and explain in allowlist (#6518) 2021-12-06 09:09:06 -08:00
Akuli
08649177f1 Add codecs.BOM* constants (#6515) 2021-12-06 17:36:09 +02:00
Akuli
bc912ea472 correct traceback.print_exception and traceback.format_exception on python 3.10 (#6512) 2021-12-06 15:43:32 +01:00
Alex Waygood
8a7c23624e Clean up signal.pyi (#6504)
This PR proposes purely cosmetic changes to make `signal.pyi` a bit neater.
2021-12-06 09:24:01 +01:00
Alex Waygood
ff4bd7c465 Add __(r)or__ to various typing classes (#6498)
- `__or__` was added to `TypeVar` in Python 3.10: https://bugs.python.org/issue41428 (this PR: https://github.com/python/cpython/pull/21515)
- `__or__` was added to `ForwardRef` in Python 3.11: https://bugs.python.org/issue45489
2021-12-05 15:16:19 -08:00
Alex Waygood
3f316b0ffb Correct signal.CTRL_C_EVENT and signal.CTRL_BREAK_EVENT (#6503) 2021-12-06 00:01:09 +02:00
Akuli
a4118b1a09 trust_server_pasv_ipv4_address: move comments to allowlists (#6496)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2021-12-05 23:59:47 +02:00
Alex Waygood
415d387009 Make various os functions available on Windows (#6500) 2021-12-05 22:06:22 +02:00
Akuli
7225dfafcf add several re-exports to posix (#6495) 2021-12-05 08:45:24 -08:00
Alex Waygood
f43b968ab9 Clean up asyncio.__init__ (#6497) 2021-12-05 16:53:26 +02:00
Shantanu
2a1ef3735d random: add VERSION, SystemRandom.getrandbits is not pos only (#6419)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-12-05 16:52:34 +02:00
Alex Waygood
bb7a06c60b Add missing asyncio functions, part II (#6493) 2021-12-05 12:29:25 +02:00
Akuli
24afb531ff stubtest_stdlib: get rid of --ignore-missing-stub (#6491)
* 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
2021-12-04 16:58:44 -08:00
Alex Waygood
f105c79219 Harmonise UserDict.__init__ with dict.__init__ (#6490)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
2021-12-04 19:50:47 +02:00
Alex Waygood
9e0ee447c6 Harmonise UserDict.fromkeys with dict.fromkeys (#6488) 2021-12-04 13:56:30 +01:00
Erik Soma
da895e3944 Correct print_exception for 3.10. (#6487) 2021-12-03 19:32:21 -08:00
Alex Waygood
a293f1e73f Add OrderedDict.fromkeys (#6485) 2021-12-03 22:06:51 +02:00
Alex Waygood
050a77d8e3 Make NewType a class in 3.10 (#6469) 2021-12-03 13:33:44 +01:00
Jelle Zijlstra
178b6bb8f4 csv: Make _Writer.write positional-only (#6475)
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`.
2021-12-02 13:27:21 -08:00
Alex Waygood
a2e4a62fac Annotate UserList.sort() .index() arguments (#6472) 2021-12-02 17:44:21 +01:00
Alex Waygood
7b24e9d89a Improve UserList comparison methods (#6471)
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.
2021-12-02 16:19:50 +01:00
Akuli
ea3f962860 Move all definitions except environ from posix to os (#6442) 2021-12-01 17:07:33 +01:00
László Károlyi
7e22a9e34a Fix datetime.strftime (#6317)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2021-11-30 23:19:30 -08:00
Shantanu
d453b74ceb logging: fix various __init__ methods (#6417)
Co-authored-by: hauntsaninja <>
2021-11-30 23:18:35 -08:00
Akuli
b3e8073bac Create unittest._log stub and improve _AssertLogsContext (#6428)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2021-11-30 21:39:14 -08:00