Skip to content

Improve Ogmios backend module #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

daehan-koreapool
Copy link
Contributor

Goals

  • Fix type hint errors
  • Improve readability and code maintainability
$ make qa
poetry run flake8 pycardano
poetry run mypy --install-types --non-interactive pycardano
pycardano/backend/ogmios.py:94: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:95: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:96: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:97: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:98: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:99: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:100: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:101: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:102: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:103: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:105: error: Item "int" of "Union[Dict[Any, Any], int]" has no attribute "get"
pycardano/backend/ogmios.py:107: error: Item "int" of "Union[Dict[Any, Any], int]" has no attribute "get"
pycardano/backend/ogmios.py:108: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:109: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:110: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:111: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:112: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:113: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:114: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:115: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:116: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:117: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:118: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:119: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:120: error: Item "int" of "Union[Dict[Any, Any], int]" has no attribute "get"
pycardano/backend/ogmios.py:123: error: Item "int" of "Union[Dict[Any, Any], int]" has no attribute "get"
pycardano/backend/ogmios.py:124: error: Item "int" of "Union[Dict[Any, Any], int]" has no attribute "get"
pycardano/backend/ogmios.py:134: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:136: error: Incompatible types in assignment (expression has type "ProtocolParameters", variable has type "None")
pycardano/backend/ogmios.py:137: error: Incompatible return value type (got "None", expected "ProtocolParameters")
pycardano/backend/ogmios.py:149: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:153: error: Incompatible types in assignment (expression has type "GenesisParameters", variable has type "None")
pycardano/backend/ogmios.py:155: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:157: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:158: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:159: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:160: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:162: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:163: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:164: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:165: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:167: error: Incompatible return value type (got "None", expected "GenesisParameters")
pycardano/backend/ogmios.py:179: error: Incompatible return value type (got "Union[Dict[Any, Any], int]", expected "int")
pycardano/backend/ogmios.py:186: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:190: error: Invalid self argument "Type[ScriptHash]" to attribute function "from_primitive" with type "Callable[[T, Union[bytes, str]], T]"
pycardano/backend/ogmios.py:191: error: Invalid self argument "Type[AssetName]" to attribute function "from_primitive" with type "Callable[[T, Union[bytes, str]], T]"
pycardano/backend/ogmios.py:191: error: Incompatible types in assignment (expression has type "Type[AssetName]", variable has type "str")
pycardano/backend/ogmios.py:237: error: Invalid self argument "Type[TransactionInput]" to attribute function "from_primitive" with type "Callable[[ArrayBase, List[Primitive]], ArrayBase]"
pycardano/backend/ogmios.py:242: error: Invalid self argument "Type[DatumHash]" to attribute function "from_primitive" with type "Callable[[T, Union[bytes, str]], T]"
pycardano/backend/ogmios.py:251: error: Argument "datum_hash" to "TransactionOutput" has incompatible type "Optional[Type[DatumHash]]"; expected "Optional[DatumHash]"
pycardano/backend/ogmios.py:267: error: Argument "datum_hash" to "TransactionOutput" has incompatible type "Optional[Type[DatumHash]]"; expected "Optional[DatumHash]"
pycardano/backend/ogmios.py:269: error: Argument 1 to "UTxO" has incompatible type "Type[TransactionInput]"; expected "TransactionInput"
pycardano/backend/ogmios.py:291: error: Item "int" of "Union[Dict[Any, Any], int]" has no attribute "__iter__" (not iterable)
pycardano/backend/ogmios.py:294: error: Invalid self argument "Type[TransactionInput]" to attribute function "from_primitive" with type "Callable[[ArrayBase, List[Primitive]], ArrayBase]"
pycardano/backend/ogmios.py:312: error: Invalid self argument "Type[DatumHash]" to attribute function "from_primitive" with type "Callable[[T, Union[bytes, str]], T]"
pycardano/backend/ogmios.py:326: error: Argument "datum_hash" to "TransactionOutput" has incompatible type "Optional[Type[DatumHash]]"; expected "Optional[DatumHash]"
pycardano/backend/ogmios.py:340: error: Argument "datum_hash" to "TransactionOutput" has incompatible type "Optional[Type[DatumHash]]"; expected "Optional[DatumHash]"
pycardano/backend/ogmios.py:344: error: Argument 1 to "UTxO" has incompatible type "Type[TransactionInput]"; expected "TransactionInput"
pycardano/backend/ogmios.py:380: error: Unsupported right operand type for in ("Union[Dict[Any, Any], int]")
pycardano/backend/ogmios.py:381: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:401: error: Unsupported right operand type for in ("Union[Dict[Any, Any], int]")
pycardano/backend/ogmios.py:404: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:405: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:406: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:407: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
pycardano/backend/ogmios.py:409: error: Value of type "Union[Dict[Any, Any], int]" is not indexable
Found 66 errors in 1 file (checked 6 source files)
make: *** [Makefile:65: qa] Error 1

@daehan-koreapool daehan-koreapool marked this pull request as draft October 27, 2022 06:56
@codecov-commenter
Copy link

codecov-commenter commented Oct 28, 2022

Codecov Report

Merging #111 (8092dc5) into main (f403c32) will increase coverage by 0.19%.
The diff coverage is 89.28%.

@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
+ Coverage   86.17%   86.36%   +0.19%     
==========================================
  Files          24       24              
  Lines        2625     2633       +8     
  Branches      515      515              
==========================================
+ Hits         2262     2274      +12     
+ Misses        269      265       -4     
  Partials       94       94              
Impacted Files Coverage Δ
pycardano/backend/ogmios.py 56.81% <78.57%> (+3.87%) ⬆️
pycardano/address.py 77.65% <100.00%> (ø)
pycardano/hash.py 96.15% <100.00%> (ø)
pycardano/key.py 86.71% <100.00%> (+0.09%) ⬆️
pycardano/metadata.py 97.26% <100.00%> (ø)
pycardano/nativescript.py 96.38% <100.00%> (ø)
pycardano/network.py 84.61% <100.00%> (+1.28%) ⬆️
pycardano/plutus.py 91.37% <100.00%> (ø)
pycardano/serialization.py 87.66% <100.00%> (ø)
pycardano/transaction.py 94.23% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@daehan-koreapool
Copy link
Contributor Author

daehan-koreapool commented Oct 28, 2022

Major Updates

  • Ensure classmethod calls are typed properly. "cls" should be typed as a Type not as an instance.

Minor Updates

  • Pull out OgmiosQueryType to avoid hardcoding query type string every single time a query is made.
  • Execute pytest before running static analyses in Github workflow so that test results are available even when static analyses fail.
  • Generalized _request() return type to Any. Will be making other helper methods for each type of query to return more specific data types in the next merge request.

I would like to refactor ogmios.py module further, but will do in the subsequent merge request to keep this merge request concise.

@daehan-koreapool daehan-koreapool marked this pull request as ready for review October 28, 2022 07:58
@daehan-koreapool daehan-koreapool changed the title WIP: Improve Ogmios backend module Improve Ogmios backend module Oct 28, 2022
@cffls cffls merged commit c5430c0 into Python-Cardano:main Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants