contrib: Fix SyntaxWarning in Python base58 implementation #19287

pull moreati wants to merge 1 commits into bitcoin:master from moreati:patch-1 changing 1 files +1 −1
  1. moreati commented at 8:37 PM on June 15, 2020: 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
    
  2. contrib: Fix SyntaxWarning in Python base58 implementation
    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
    ```
    47b49a05ea
  3. DrahtBot added the label Scripts and tools on Jun 15, 2020
  4. MarcoFalke commented at 11:17 PM on June 15, 2020: 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?

  5. moreati commented at 5:59 AM on June 16, 2020: contributor

    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.

  6. moreati commented at 6:40 PM on June 16, 2020: contributor

    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

  7. MarcoFalke commented at 6:51 PM on June 16, 2020: member

    ACK 47b49a05eafddcaef373f70436d794e9f9f7495c

  8. fanquake merged this on Jun 17, 2020
  9. fanquake closed this on Jun 17, 2020

  10. practicalswift commented at 2:00 PM on June 17, 2020: contributor

    Post-merge ACK 47b49a05eafddcaef373f70436d794e9f9f7495c

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

  11. PastaPastaPasta referenced this in commit 63da95249c on Jun 27, 2021
  12. PastaPastaPasta referenced this in commit 7ab058a0fb on Jun 28, 2021
  13. PastaPastaPasta referenced this in commit 5bc6ee02a4 on Jun 29, 2021
  14. PastaPastaPasta referenced this in commit 34e3de25e2 on Jul 1, 2021
  15. PastaPastaPasta referenced this in commit 06e4da9c5e on Jul 1, 2021
  16. PastaPastaPasta referenced this in commit a4ccdd8886 on Sep 17, 2021
  17. PastaPastaPasta referenced this in commit 016320f715 on Sep 19, 2021
  18. thelazier referenced this in commit d4821ff7f6 on Sep 25, 2021
  19. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 12:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me