Skip to content

contrib: Fix SyntaxWarning in Python base58 implementation - #19287

Merged
fanquake merged 1 commit into
bitcoin:masterfrom
moreati:patch-1
Jun 17, 2020
Merged

fanquake merged 1 commit into
bitcoin:masterfrom
moreati:patch-1

Conversation

@moreati

@moreati moreati commented Jun 15, 2020 •

Copy link
Copy Markdown
Contributor

In Python integers should be compared for equality (i == j), not identity (i is j). Recent versions of CPython 3.x emit a SyntaxWarning when they encounter this incorrect usage, e.g.

$ python3 base58.py 
base58.py:110: SyntaxWarning: "is" with a literal. Did you mean "=="?
  assert get_bcaddress_version('15VjRaDX9zpbA8LVnbrCAFzrVzN7ixHNsC') is 0
Tests passed

In Python integers should be compared for equality (`i == j`), not identity (`i is j`). Recent versions of CPython 3.x emit a SyntaxWarning when they encounter this incorrect usage, e.g.

```
$ python3 base58.py 
base58.py:110: SyntaxWarning: "is" with a literal. Did you mean "=="?
  assert get_bcaddress_version('15VjRaDX9zpbA8LVnbrCAFzrVzN7ixHNsC') is 0
Tests passed
```
@maflcko

maflcko commented Jun 15, 2020

Copy link
Copy Markdown
Member

Concept ACK. As I understand it is should only be used to check for "pointer-equality" and IIRC the only built-in type where that is acceptable (and maybe recommended) to use is None.

Did you also check the functional test files and other python files in this repo for similar sharp edges?

@moreati

moreati commented Jun 16, 2020

Copy link
Copy Markdown
Contributor Author

Concept ACK. As I understand it is should only be used to check for "pointer-equality"

'is is roughly equivalent to comparing pointers in C. As an implementation detail of CPython (not PyPy or others) x is y actually compares memory addresses, because on CPython id(x) returns the memory address of x.

the only built-in type where that is acceptable (and maybe recommended) to use is None.

True 99% of the time, mainly because None is a singleton. There are a few, rare corner cases, e,g. using an object() as a sentinel value https://python-patterns.guide/python/sentinel-object/

Did you also check the functional test files and other python files in this repo for similar sharp edges?

I didn't. I will.

@moreati

moreati commented Jun 16, 2020 •

Copy link
Copy Markdown
Contributor Author

No other files matching '*.py' exhibit this problem.

I also did a brief eyeball scan. Overall the Python scripts/modules look okay. A few suggestions

@maflcko

maflcko commented Jun 16, 2020

Copy link
Copy Markdown
Member

ACK 47b49a0

@fanquake
fanquake merged commit 09da0e4 into bitcoin:master Jun 17, 2020
@practicalswift

Copy link
Copy Markdown
Contributor

Post-merge ACK 47b49a0

Warm welcome as a contributor @moreati! Thanks for reviewing the Python code in the repo.

PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 1, 2021
…ementation

47b49a0 contrib: Fix SyntaxWarning in Python base58 implementation (Alex Willmer)

Pull request description:

  In Python integers should be compared for equality (`i == j`), not identity (`i is j`). Recent versions of CPython 3.x emit a SyntaxWarning when they encounter this incorrect usage, e.g.

  ```
  $ python3 base58.py
  base58.py:110: SyntaxWarning: "is" with a literal. Did you mean "=="?
    assert get_bcaddress_version('15VjRaDX9zpbA8LVnbrCAFzrVzN7ixHNsC') is 0
  Tests passed
  ```

ACKs for top commit:
  MarcoFalke:
    ACK 47b49a0

Tree-SHA512: 9f8962025dcdfa062c0515c68a1864f5bbeb86bd0510c0ec0e413a5edb6afbfd5f41b4c0255784e53db8eaf39c68b7cfa7cc8a33a2e5214aae463fda374f8719
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 19, 2021
…ementation

47b49a0 contrib: Fix SyntaxWarning in Python base58 implementation (Alex Willmer)

Pull request description:

  In Python integers should be compared for equality (`i == j`), not identity (`i is j`). Recent versions of CPython 3.x emit a SyntaxWarning when they encounter this incorrect usage, e.g.

  ```
  $ python3 base58.py
  base58.py:110: SyntaxWarning: "is" with a literal. Did you mean "=="?
    assert get_bcaddress_version('15VjRaDX9zpbA8LVnbrCAFzrVzN7ixHNsC') is 0
  Tests passed
  ```

ACKs for top commit:
  MarcoFalke:
    ACK 47b49a0

Tree-SHA512: 9f8962025dcdfa062c0515c68a1864f5bbeb86bd0510c0ec0e413a5edb6afbfd5f41b4c0255784e53db8eaf39c68b7cfa7cc8a33a2e5214aae463fda374f8719
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants