Skip to content

Conversation

kiminuo
Copy link
Contributor

@kiminuo kiminuo commented Jan 17, 2021

Motivation

When I wanted to understand better https://github.com/bitcoin/bitcoin/pull/19145/files#diff-4bebbd3b112dc222ea7e75ef051838ceffcee63b9e9234a98a4cc7251d34451b test, I noticed that navigation in PyCharm/VS Code did not work for nodes variable. I think this is frustrating, especially for newcomers.

Summary

  • This PR modifies Python 3.5 type comments to Python 3.6+ types and adds a proper type for nodes instance attribute.
  • This PR does not change behavior.
  • This PR is intentionally very small, if the concept is accepted, a follow-up PRs can be more ambitious.

End result

  1. Open test/functional/feature_abortnode.py
  2. Move your caret to: self.nodes[0].generate[caret here](3)
  3. Use "Go to definition" [F12] should work now.

I have tested this on PyCharm (Windows, Ubuntu) and VS Code (Windows, Ubuntu).

Note: Some TestNode methods (e.g. self.nodes[0].getblock(...) ) use __call__ mechanism and navigation does not work for them even with this PR.

@DrahtBot DrahtBot added the Tests label Jan 17, 2021
@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

… comments to Python 3.6+ types. Additionally, set type for "nodes".
@kiminuo kiminuo force-pushed the feature/202101-test_framework-types branch from d82511c to 5353b0c Compare January 18, 2021 08:01
@kiminuo kiminuo marked this pull request as ready for review January 18, 2021 08:09
Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the types be added in all vars (network_thread, rpc_timeout..)?

@kiminuo
Copy link
Contributor Author

kiminuo commented Jan 18, 2021

Shouldn't the types be added in all vars (network_thread, rpc_timeout..)?

Yes but as I wrote in the description "This PR is intentionally very small, if the concept is accepted, a follow-up PRs can be more ambitious."

@laanwj
Copy link
Member

laanwj commented Jan 18, 2021

Looks correct to me (and the CI does mypy checks on the test framework).
ACK 5353b0c

@brunoerg
Copy link
Contributor

Shouldn't the types be added in all vars (network_thread, rpc_timeout..)?

Yes but as I wrote in the description "This PR is intentionally very small, if the concept is accepted, a follow-up PRs can be more ambitious."

No problem. Concept ACK.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious and tried this out with PyCharm 2020.3.3 (Community Edition) and Python 3.9.1 under Win10. Navigation to the implementation of generate via Ctrl-Alt-B (I guess the proposed shortcut F12 is avilable in VSCode?) did work both in master and PR branch.

That said, the patch looks correct.

ACK 5353b0c

@maflcko maflcko merged commit 4c55f92 into bitcoin:master Jan 31, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 2, 2021
5353b0c Change type definitions for "chain" and "setup_clean_chain" from type comments to Python 3.6+ types. Additionally, set type for "nodes". (Kiminuo)

Pull request description:

  ### Motivation

  When I wanted to understand better https://github.com/bitcoin/bitcoin/pull/19145/files#diff-4bebbd3b112dc222ea7e75ef051838ceffcee63b9e9234a98a4cc7251d34451b test, I noticed that navigation in PyCharm/VS Code did not work for `nodes` variable. I think this is frustrating, especially for newcomers.

  ### Summary

  * This PR modifies Python 3.5 [type comments](https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#variables) to Python 3.6+ types and adds a proper type for `nodes` [instance attribute](https://mypy.readthedocs.io/en/stable/class_basics.html#instance-and-class-attributes).
  * This PR does not change behavior.
  * This PR is intentionally very small, if the concept is accepted, a follow-up PRs can be more ambitious.

  ### End result

  1. Open `test/functional/feature_abortnode.py`
  2. Move your caret to: `self.nodes[0].generate[caret here](3)`
  3. Use "Go to definition" [F12] should work now.

  I have tested this on PyCharm (Windows, Ubuntu) and VS Code (Windows, Ubuntu).

  Note: Some `TestNode` methods (e.g. `self.nodes[0].getblock(...)` ) use `__call__` mechanism and navigation does not work for them even with this PR.

ACKs for top commit:
  laanwj:
    ACK 5353b0c
  theStack:
    ACK 5353b0c

Tree-SHA512: 821773f052ab9b2889dc357d38c59407a4af09e3b86d7134fcca7d78e5edf3a5ede9bfb37595ea97caf9ebfcbda372bcf73763b7f89b0677670f21b3e396a12b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 17, 2021
5353b0c Change type definitions for "chain" and "setup_clean_chain" from type comments to Python 3.6+ types. Additionally, set type for "nodes". (Kiminuo)

Pull request description:

  ### Motivation

  When I wanted to understand better https://github.com/bitcoin/bitcoin/pull/19145/files#diff-4bebbd3b112dc222ea7e75ef051838ceffcee63b9e9234a98a4cc7251d34451b test, I noticed that navigation in PyCharm/VS Code did not work for `nodes` variable. I think this is frustrating, especially for newcomers.

  ### Summary

  * This PR modifies Python 3.5 [type comments](https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#variables) to Python 3.6+ types and adds a proper type for `nodes` [instance attribute](https://mypy.readthedocs.io/en/stable/class_basics.html#instance-and-class-attributes).
  * This PR does not change behavior.
  * This PR is intentionally very small, if the concept is accepted, a follow-up PRs can be more ambitious.

  ### End result

  1. Open `test/functional/feature_abortnode.py`
  2. Move your caret to: `self.nodes[0].generate[caret here](3)`
  3. Use "Go to definition" [F12] should work now.

  I have tested this on PyCharm (Windows, Ubuntu) and VS Code (Windows, Ubuntu).

  Note: Some `TestNode` methods (e.g. `self.nodes[0].getblock(...)` ) use `__call__` mechanism and navigation does not work for them even with this PR.

ACKs for top commit:
  laanwj:
    ACK 5353b0c
  theStack:
    ACK 5353b0c

Tree-SHA512: 821773f052ab9b2889dc357d38c59407a4af09e3b86d7134fcca7d78e5edf3a5ede9bfb37595ea97caf9ebfcbda372bcf73763b7f89b0677670f21b3e396a12b
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 1, 2022
Summary:
> I noticed that navigation in PyCharm/VS Code did not work for nodes variable. I think this is frustrating, especially for newcomers.

This will make python IDEs work better with the test framework.
Our code already switched to python 3.6 types hints for `chain` and `setup_clean_chain`, so the only change for these attributes is to remove `Optional`.

This is a backport of [[bitcoin/bitcoin#20954 | core#20954]]

Test Plan: `ninja check-functional`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10949
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants