Commit Graph

182 Commits

Author SHA1 Message Date
Alex Waygood 4b107d86f3
gh-104683: clinic.py: Modernise `parse_converter()` using pattern-matching (#104696) 2023-05-21 23:29:43 +00:00
Erlend E. Aasland 6ba8406cb6
gh-104050: Add more type annotations to Argument Clinic (#104631)
Annotate methods of the following classes:

- class Function
- class Parameter
- class LandMine
2023-05-21 21:24:26 +00:00
Erlend E. Aasland bf6dd8f5fd
gh-104050: Add basic type hints to Argument Clinic clinic class (#104705)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-21 20:49:34 +00:00
Erlend E. Aasland c482e9a4e6
gh-104050: Annotate Argument Clinic return converters (#104706)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-21 20:23:14 +00:00
Erlend E. Aasland 27a68be77f
gh-104050: Add basic type hints to Argument Clinic DSL parser (#104704)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-20 21:55:02 +00:00
Alex Waygood 19dd5aa89a
gh-104683: Modernise Tools/clinic/ (#104684)
- Make some string interpolations more readable using f-strings or
  explicit parametrisation
- Remove unneeded open() mode specifiers

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-05-20 20:16:49 +00:00
Alex Waygood 663c049ff7
gh-104683: Modernise `clinic.py` using `str.removeprefix` and `str.removesuffix` (#104685)
Both methods were new in Python 3.9.
2023-05-20 11:08:28 +00:00
Erlend E. Aasland ae147d01a0
gh-104146: Purge dead code from Argument Clinic (#104680)
The following local variables were assigned but never used:

- line 551:  result
- line 1341: groups
- line 1431: default_return_converter
- line 1529: ignore_self
- line 1809: input_checksum
- line 4224: new'

---

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-20 10:52:32 +00:00
Alex Waygood 02b60035ce
gh-104683: Argument clinic: use `dict` over `OrderedDict` (#104647)
For code readability. Instances of `builtins.dict` have been ordered since 3.6, and have been guaranteed by the language to be ordered since Python 3.7. Argument Clinic now requires Python 3.10+.
2023-05-20 11:24:00 +01:00
Erlend E. Aasland 94c8edabd3
gh-104050: Add more type annotations to Argument Clinic (#104628)
Annotate the following:

- methods of class Class
- methods of class Module
- methods of class PythonParser
- function compute_checksum()
- function parse_file()
- global variable unsupported_special_methods
2023-05-18 22:57:26 +00:00
Alex Waygood 1c55e8d007
gh-104050: Improve some typing around `default`s and sentinel values (#104626)
- Convert `unspecified` and `unknown` to be members of a `Sentinels` enum, rather than instances of bespoke classes.
  - An enum feels more idiomatic here, and works better with type checkers.
  - Convert some `==` and `!=` checks for these values to identity checks, which are more idiomatic with sentinels.
  - _Don't_ do the same for `Null`, as this needs to be a distinct type due to its usage in `clinic.py`.
- Use `object` as the annotation for `default` across `clinic.py`. `default` can be literally any object, so `object` is the correct annotation here.

---

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-05-18 21:58:42 +00:00
Erlend E. Aasland 61027c0211
gh-104146: Remove unused vars from Argument Clinic (#104627)
Remove 'in_classes' and 'so_far' from DSLParser.directive_module()
2023-05-18 21:52:59 +00:00
Erlend E. Aasland 2f369cafee
gh-104050: Add type hints to Argument Clinic converter keywords (#104588)
Introduce TypeSet, and use it to annotate the 'accept' keyword of
various C converters. Also add some missing return annotations for
converter init functions.
2023-05-17 21:05:22 +00:00
Erlend E. Aasland 0afc473f50
gh-104050: Add typing to Argument Clinic converters (#104547) 2023-05-16 22:32:11 +00:00
Nikita Sobolev a454a6651b
gh-104050: Add more annotations to `Tools/clinic.py` (#104544) 2023-05-16 17:18:28 +00:00
Erlend E. Aasland c22fced96c
gh-104050: Don't star-import 'types' in Argument Clinic (#104543) 2023-05-16 12:02:18 +00:00
Erlend E. Aasland 505e2954a9
gh-104050: Add basic typing to CConverter in clinic.py (#104538) 2023-05-16 11:47:35 +00:00
Erlend E. Aasland cca90b6906
gh-64595: Fix write file logic in Argument Clinic (#104507)
Check if any clinic output actually changes any of the output files
before deciding if we should touch the source file.
2023-05-16 12:25:43 +02:00
dependabot[bot] 35bf0916d9
Bump mypy from 1.2.0 to 1.3.0 in /Tools/clinic (#104501)
build(deps-dev): bump mypy from 1.2.0 to 1.3.0 in /Tools/clinic

Bumps [mypy](https://github.com/python/mypy) from 1.2.0 to 1.3.0.
- [Commits](https://github.com/python/mypy/compare/v1.2.0...v1.3.0)

---
updated-dependencies:
- dependency-name: mypy
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-15 09:17:48 +00:00
Alex Waygood 9d41f83c58
gh-104050: Run mypy on `clinic.py` in CI (#104421)
* Add basic mypy workflow to CI
* Make the type check pass

---------

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2023-05-15 08:49:28 +00:00
Erlend E. Aasland b2c1b4da19
gh-104389: Add 'unused' keyword to Argument Clinic C converters (#104390)
Use the unused keyword param in the converter to explicitly
mark an argument as unused:

    /*[clinic input]
    SomeBaseClass.stubmethod
        flag: bool(unused=True)
    [clinic start generated code]*/
2023-05-12 10:34:00 +02:00
Alex Waygood fe694a6db6
gh-90953: Don't use deprecated AST nodes in clinic.py (#104322) 2023-05-09 22:16:22 +01:00
Erlend E. Aasland ac020624b3
gh-64660: Don't hardcode Argument Clinic return converter result variable name (#104200) 2023-05-07 21:55:37 +00:00
Erlend E. Aasland 66558d2a16
gh-104146: Remove unused var 'parser_body_declarations' from clinic.py (#104214) 2023-05-05 21:35:24 +00:00
Erlend E. Aasland 45a9e3834a
gh-64595: Argument Clinic: Touch source file if any output file changed (#104152) 2023-05-05 12:38:38 +00:00
Erlend E. Aasland 5245cb64d9
gh-68395: Avoid naming conflicts by mangling variable names in Argument Clinic (#104065)
Add all internally used variable names to CLINIC_PREFIXED_ARGS.
2023-05-05 13:40:18 +02:00
Erlend E. Aasland 9885677b04
gh-104146: Remove unused 'second_pass_replacements' from clinic.py (#104147)
The code that manipulated 'second_pass_replacements' was removed in 2015
with commit 0759f84 (gh-67688, bpo-23500).
2023-05-04 00:11:29 +00:00
Erlend E. Aasland 2753cf2ed6
gh-101409: Improve generated clinic code for self type checks (#101411) 2023-01-31 21:42:03 +01:00
Nikita Sobolev 3da71ff0f2
Fix copy-paste error in `Tools/clinic.py` (#100560) 2022-12-28 09:57:57 +05:30
Kumar Aditya 7cf164ad5e
GH-100342: check for allocation failure in AC `*args` parsing (#100343) 2022-12-28 09:46:28 +05:30
Nikita Sobolev b0ea28913e
Remove `NoneType` redefinition from `clinic.py` (#100551) 2022-12-27 21:41:39 +05:30
Shantanu 621a1790c4
gh-100176: remove incorrect version compatibility check from argument clinic (#100190) 2022-12-12 17:22:12 +05:30
colorfulappl 0da728387c
gh-64490: Fix bugs in argument clinic varargs processing (#32092) 2022-11-24 20:56:50 +01:00
colorfulappl 8dbe08eb7c
gh-99240: Fix double-free bug in Argument Clinic str_converter generated code (GH-99241)
Fix double-free bug mentioned at https://github.com/python/cpython/issues/99240,
by moving memory clean up out of "exit" label.

Automerge-Triggered-By: GH:erlend-aasland
2022-11-24 06:01:26 -08:00
colorfulappl 69f6cc77d0
gh-64490: Fix refcount error when arguments are packed to tuple in argument clinic (#99233) 2022-11-24 17:54:18 +05:30
Irit Katriel 34e6f3567e
gh-92886: [clinic.py] raise exception on invalid input instead of assertion (GH-98051)
Tests should pass with -O (assertions off).

Automerge-Triggered-By: GH:iritkatriel
2022-10-07 14:41:35 -07:00
Serhiy Storchaka 0ee9619a4c
gh-97728: Argument Clinic: Fix uninitialized variable in the Py_UNICODE converter (GH-97729)
It affects function os.system() on Windows and Windows-specific modules
winreg, _winapi, _overlapped, and _msi.
2022-10-03 10:42:54 +03:00
Erlend E. Aasland f07adf82f3
gh-90928: Improve static initialization of keywords tuple in AC (#95907) 2022-08-13 12:09:40 +02:00
Eric Snow 6f6a4e6cc5
gh-90928: Statically Initialize the Keywords Tuple in Clinic-Generated Code (gh-95860)
We only statically initialize for core code and builtin modules.  Extension modules still create
the tuple at runtime.  We'll solve that part of interpreter isolation separately.

This change includes generated code. The non-generated changes are in:

* Tools/clinic/clinic.py
* Python/getargs.c
* Include/cpython/modsupport.h
* Makefile.pre.in (re-generate global strings after running clinic)
* very minor tweaks to Modules/_codecsmodule.c and Python/Python-tokenize.c

All other changes are generated code (clinic, global strings).
2022-08-11 15:25:49 -06:00
Serhiy Storchaka 74b5e4ce80
gh-95007: Remove the NoneType return converter (GH-95019)
It has confusing semantic which does not provide any benefit (the
only difference is that you should write "return Py_None" instead
of "Py_RETURN_NONE"), it is not currently used, and it is broken.
2022-07-20 08:42:02 +03:00
Erlend Egeberg Aasland 8bbd70b4d1
gh-94430: Allow params named `module` or `self` with custom C names in Argument Clinic (#94431) 2022-07-07 11:29:34 +02:00
Erlend Egeberg Aasland 2b8ed4d3d4
gh-94538: Fix Argument Clinic output to custom file (#94539) 2022-07-05 11:06:04 +02:00
Victor Stinner 47e35625ff
gh-84623: Remove unused imports (#94132) 2022-06-22 19:14:27 +02:00
Inada Naoki f9c9354a7a
gh-92536: PEP 623: Remove wstr and legacy APIs from Unicode (GH-92537) 2022-05-12 14:48:38 +09:00
Erlend Egeberg Aasland 4bd07d1dbd
gh-92256: Improve Argument Clinic parser error messages (#92268)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2022-05-10 09:23:42 +02:00
Victor Stinner b270b82f11
gh-91320: Argument Clinic uses _PyCFunction_CAST() (#32210)
Replace "(PyCFunction)(void(*)(void))func" cast with
_PyCFunction_CAST(func).
2022-05-03 20:25:41 +02:00
Serhiy Storchaka a055dac0b4
gh-91583: AC: Fix regression for functions with defining_class (GH-91739)
Argument Clinic now generates the same efficient code as before
adding the defining_class parameter.
2022-04-30 13:15:02 +03:00
Victor Stinner 042f31da55
bpo-45459: C API uses type names rather than structure names (GH-31528)
Thanks to the new pytypedefs.h, it becomes to use type names like
PyObject rather like structure names like "struct _object".
2022-02-24 17:51:59 +01:00
Serhiy Storchaka d8a464ef03
Remove an outdated comment. (GH-30010) 2021-12-09 20:44:36 +02:00
Serhiy Storchaka 92bf8691fb
bpo-43413: Fix handling keyword arguments in subclasses of some buitin classes (GH-26456)
* Constructors of subclasses of some buitin classes (e.g. tuple, list,
  frozenset) no longer accept arbitrary keyword arguments.
* Subclass of set can now define a __new__() method with additional
  keyword parameters without overriding also __init__().
2021-09-12 13:27:50 +03:00