[v2,00/10] Add typing annotations to gdbarch*.py and make-target-delegates.py

Message ID 20230225033047.373899-1-simon.marchi@polymtl.ca
Headers
Series Add typing annotations to gdbarch*.py and make-target-delegates.py |

Message

Simon Marchi Feb. 25, 2023, 3:30 a.m. UTC
  v2 of:

https://inbox.sourceware.org/gdb-patches/877cw6hma2.fsf@tromey.com/T/#t

Patch "gdb: gdbarch.py: remove Info.__init__" is new, the rest hasn't
changed.

Simon Marchi (10):
  gdb: remove invalid / dead code from gdbarch.py
  gdb: reformat Python files with black 23.1.0
  gdb: gdbarch.py: spell out parameters of _Component.__init__
  gdb: gdbarch.py: remove Info.__init__
  gdb: pyproject.toml: set pyright typeCheckingMode = "strict"
  gdb: split gdbarch component types to gdbarch_types.py
  gdb: gdbarch*.py, copyright.py: add type annotations
  gdb: make-target-delegates.py: make one string raw
  gdb: make-target-delegates.py: add Entry type
  gdb: make-target-delegates.py: add type annotations

 gdb/gdbarch.py                                | 161 +--------------
 ...ch-components.py => gdbarch_components.py} |   7 +-
 gdb/gdbarch_types.py                          | 184 ++++++++++++++++++
 gdb/gdbcopyright.py                           |   2 +-
 gdb/make-target-delegates.py                  | 104 +++++++---
 gdb/pyproject.toml                            |   3 +
 gdb/python/lib/gdb/FrameDecorator.py          |   1 -
 gdb/python/lib/gdb/command/frame_filters.py   |   1 +
 gdb/python/lib/gdb/dap/server.py              |   2 +-
 gdb/python/lib/gdb/printing.py                |   2 +-
 .../gdb.multi/multi-target-info-inferiors.py  |   1 +
 gdb/testsuite/gdb.perf/backtrace.py           |   1 -
 .../gdb.python/py-framefilter-addr.py         |   1 +
 gdb/testsuite/gdb.python/py-framefilter.py    |   1 +
 gdb/testsuite/gdb.python/py-inferior-leak.py  |   2 +
 gdb/testsuite/gdb.python/py-prettyprint.py    |   1 +
 gdb/testsuite/gdb.python/py-recurse-unwind.py |   5 -
 gdb/testsuite/gdb.python/py-send-packet.py    |   1 +
 gdb/testsuite/gdb.python/tui-window.py        |   1 +
 19 files changed, 285 insertions(+), 196 deletions(-)
 rename gdb/{gdbarch-components.py => gdbarch_components.py} (99%)
 create mode 100755 gdb/gdbarch_types.py


base-commit: 95ebc6fdec5780bf59685739cdd55cd41d0f55ac
  

Comments

Andrew Burgess Feb. 25, 2023, 11:05 a.m. UTC | #1
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

> v2 of:
>
> https://inbox.sourceware.org/gdb-patches/877cw6hma2.fsf@tromey.com/T/#t
>
> Patch "gdb: gdbarch.py: remove Info.__init__" is new, the rest hasn't
> changed.
>
> Simon Marchi (10):
>   gdb: remove invalid / dead code from gdbarch.py
>   gdb: reformat Python files with black 23.1.0
>   gdb: gdbarch.py: spell out parameters of _Component.__init__
>   gdb: gdbarch.py: remove Info.__init__
>   gdb: pyproject.toml: set pyright typeCheckingMode = "strict"
>   gdb: split gdbarch component types to gdbarch_types.py
>   gdb: gdbarch*.py, copyright.py: add type annotations
>   gdb: make-target-delegates.py: make one string raw
>   gdb: make-target-delegates.py: add Entry type
>   gdb: make-target-delegates.py: add type annotations

Hi Simon,

I tried this series and I now get this error when rerunning gdbarch.py:

  $ ./gdbarch.py 
  Traceback (most recent call last):
    File "./gdbarch.py", line 26, in <module>
      import gdbarch_components  # noqa: F401 # type: ignore
    File "/home/andrew/projects/binutils-gdb/src.dev-2/gdb/gdbarch_components.py", line 120, in <module>
      from gdbarch_types import Function, Info, Method, Value
    File "/home/andrew/projects/binutils-gdb/src.dev-2/gdb/gdbarch_types.py", line 31, in <module>
      def join_params(params: list[tuple[str, str]]):
  TypeError: 'type' object is not subscriptable
  $ python --version
  Python 3.7.9

Any thoughts?

Thanks,
Andrew

>
>  gdb/gdbarch.py                                | 161 +--------------
>  ...ch-components.py => gdbarch_components.py} |   7 +-
>  gdb/gdbarch_types.py                          | 184 ++++++++++++++++++
>  gdb/gdbcopyright.py                           |   2 +-
>  gdb/make-target-delegates.py                  | 104 +++++++---
>  gdb/pyproject.toml                            |   3 +
>  gdb/python/lib/gdb/FrameDecorator.py          |   1 -
>  gdb/python/lib/gdb/command/frame_filters.py   |   1 +
>  gdb/python/lib/gdb/dap/server.py              |   2 +-
>  gdb/python/lib/gdb/printing.py                |   2 +-
>  .../gdb.multi/multi-target-info-inferiors.py  |   1 +
>  gdb/testsuite/gdb.perf/backtrace.py           |   1 -
>  .../gdb.python/py-framefilter-addr.py         |   1 +
>  gdb/testsuite/gdb.python/py-framefilter.py    |   1 +
>  gdb/testsuite/gdb.python/py-inferior-leak.py  |   2 +
>  gdb/testsuite/gdb.python/py-prettyprint.py    |   1 +
>  gdb/testsuite/gdb.python/py-recurse-unwind.py |   5 -
>  gdb/testsuite/gdb.python/py-send-packet.py    |   1 +
>  gdb/testsuite/gdb.python/tui-window.py        |   1 +
>  19 files changed, 285 insertions(+), 196 deletions(-)
>  rename gdb/{gdbarch-components.py => gdbarch_components.py} (99%)
>  create mode 100755 gdb/gdbarch_types.py
>
>
> base-commit: 95ebc6fdec5780bf59685739cdd55cd41d0f55ac
> -- 
> 2.39.2
  
Simon Marchi Feb. 27, 2023, 1:11 a.m. UTC | #2
On 2/25/23 06:05, Andrew Burgess wrote:
> Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
>> v2 of:
>>
>> https://inbox.sourceware.org/gdb-patches/877cw6hma2.fsf@tromey.com/T/#t
>>
>> Patch "gdb: gdbarch.py: remove Info.__init__" is new, the rest hasn't
>> changed.
>>
>> Simon Marchi (10):
>>   gdb: remove invalid / dead code from gdbarch.py
>>   gdb: reformat Python files with black 23.1.0
>>   gdb: gdbarch.py: spell out parameters of _Component.__init__
>>   gdb: gdbarch.py: remove Info.__init__
>>   gdb: pyproject.toml: set pyright typeCheckingMode = "strict"
>>   gdb: split gdbarch component types to gdbarch_types.py
>>   gdb: gdbarch*.py, copyright.py: add type annotations
>>   gdb: make-target-delegates.py: make one string raw
>>   gdb: make-target-delegates.py: add Entry type
>>   gdb: make-target-delegates.py: add type annotations
> 
> Hi Simon,
> 
> I tried this series and I now get this error when rerunning gdbarch.py:
> 
>   $ ./gdbarch.py 
>   Traceback (most recent call last):
>     File "./gdbarch.py", line 26, in <module>
>       import gdbarch_components  # noqa: F401 # type: ignore
>     File "/home/andrew/projects/binutils-gdb/src.dev-2/gdb/gdbarch_components.py", line 120, in <module>
>       from gdbarch_types import Function, Info, Method, Value
>     File "/home/andrew/projects/binutils-gdb/src.dev-2/gdb/gdbarch_types.py", line 31, in <module>
>       def join_params(params: list[tuple[str, str]]):
>   TypeError: 'type' object is not subscriptable
>   $ python --version
>   Python 3.7.9
> 
> Any thoughts?

Ah, that's because using the built-in types (like `list`) only works
starting with 3.9.  So I should use the types from the typing module,
like `List`:

https://docs.python.org/3.7/library/typing.html#typing.List

I'll send a v3 with that changed.

Simon