Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

fixing TrytesCompatible so that its no longer generic. #343

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

bschnurr
Copy link

@bschnurr bschnurr commented May 7, 2021

Description of change

Fixes an error found by using the Pylance LS in basic typechecking mode.
image

I'm assuming the original code was meant to be "str or bytes". Most the docstrings mention Byte string or bytearray.
Using a constrained TypeVar like AnyStr in a Union is usually a mistake.

TrytesCompatible = Union[AnyStr, bytearray, 'TryteString'] defines a generic type alias, which can be legitimate. To use it properly, you'd need to provide a type argument that is compatible with the AnyStr type variable.

TrytesCompatible[str] or TrytesCompatible[bytes] or TrytesCompatible[AnyStr] would all be allowed.

Type of change

Choose a type of change, and delete any options that are not relevant.

  • Bug fix (a non-breaking change which fixes an issue)

How the change has been tested

Ran all tests
python setup.py test

Change checklist

Add an x to the boxes that are relevant to your changes, and delete any items that are not.

  • My code follows the contribution guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (docs/ directory and/or docstrings in source code)
  • I have followed PEP-8 Style Guide in my code.
  • New and existing unit tests pass locally with my changes

…is is a mistake based on usage.

TrytesCompatible = Union[AnyStr, bytearray, 'TryteString'] defines a generic type alias, which can be legitimate. To use it properly, you'd need to provide a type argument that is compatible with the AnyStr type variable.

TrytesCompatible[str] or TrytesCompatible[bytes] or TrytesCompatible[AnyStr] would all be allowed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant