Skip to content
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

Improve base + blockfrost module maintainability #120

Merged
merged 16 commits into from
Nov 7, 2022

Conversation

daehan-koreapool
Copy link
Contributor

Background

  • Optional attributes in GenesisParameters and ProtocolParameters raises various errors.
  • Updating these dataclasses to be non-optional and frozen/immutable would produce less errors in the future in my opinion.

Goals

  • Update GenesisParameters and ProtocolParameters to be non-optional and frozen
$ make qa
poetry run flake8 pycardano
poetry run mypy --install-types --non-interactive pycardano
pycardano/backend/base.py:26: error: Incompatible types in assignment (expression has type "None", variable has type "float")
pycardano/backend/base.py:28: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:30: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:32: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:34: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:36: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:38: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:40: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:42: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:44: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:51: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:53: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:55: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:57: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:59: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:61: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:63: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:65: error: Incompatible types in assignment (expression has type "None", variable has type "float")
pycardano/backend/base.py:67: error: Incompatible types in assignment (expression has type "None", variable has type "float")
pycardano/backend/base.py:69: error: Incompatible types in assignment (expression has type "None", variable has type "float")
pycardano/backend/base.py:71: error: Incompatible types in assignment (expression has type "None", variable has type "float")
pycardano/backend/base.py:73: error: Incompatible types in assignment (expression has type "None", variable has type "str")
pycardano/backend/base.py:75: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:77: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:79: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:81: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:83: error: Incompatible types in assignment (expression has type "None", variable has type "float")
pycardano/backend/base.py:85: error: Incompatible types in assignment (expression has type "None", variable has type "float")
pycardano/backend/base.py:87: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:89: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:91: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:93: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:95: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:97: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:99: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:101: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:103: error: Incompatible types in assignment (expression has type "None", variable has type "int")
pycardano/backend/base.py:105: error: Incompatible types in assignment (expression has type "None", variable has type "Dict[str, Dict[str, int]]")
pycardano/backend/blockfrost.py:76: error: Incompatible return value type (got "None", expected "int")
pycardano/backend/blockfrost.py:87: error: Incompatible types in assignment (expression has type "GenesisParameters", variable has type "None")
pycardano/backend/blockfrost.py:88: error: Incompatible return value type (got "None", expected "GenesisParameters")
pycardano/backend/blockfrost.py:94: error: Incompatible types in assignment (expression has type "ProtocolParameters", variable has type "None")
pycardano/backend/blockfrost.py:126: error: Incompatible return value type (got "None", expected "ProtocolParameters")
pycardano/backend/blockfrost.py:141: error: Invalid self argument "Type[NativeScript]" to attribute function "from_dict" with type "Callable[[NativeScript, Dict[Any, Any], bool], Union[ScriptPubkey, ScriptAll, ScriptAny, ScriptNofK, InvalidBefore, InvalidHereAfter]]"
pycardano/backend/blockfrost.py:170: error: Argument 1 to "Value" has incompatible type "Optional[int]"; expected "int"
Found 45 errors in 2 files (checked 8 source files)
make: *** [Makefile:65: qa] Error 1

@codecov-commenter
Copy link

codecov-commenter commented Nov 3, 2022

Codecov Report

Merging #120 (4989531) into main (69349fb) will increase coverage by 0.09%.
The diff coverage is 90.62%.

@@            Coverage Diff             @@
##             main     #120      +/-   ##
==========================================
+ Coverage   85.81%   85.91%   +0.09%     
==========================================
  Files          24       25       +1     
  Lines        2664     2690      +26     
  Branches      519      517       -2     
==========================================
+ Hits         2286     2311      +25     
- Misses        284      286       +2     
+ Partials       94       93       -1     
Impacted Files Coverage Δ
pycardano/backend/blockfrost.py 33.61% <61.53%> (+3.61%) ⬆️
pycardano/backend/ogmios.py 55.18% <77.77%> (+1.08%) ⬆️
pycardano/backend/base.py 100.00% <100.00%> (ø)
pycardano/nativescript.py 97.84% <100.00%> (+1.46%) ⬆️
pycardano/types.py 100.00% <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

Major Updates

  • Enforcing GenesisParameters and ProtocolParameters to be frozen dataclasses with non-optional attributes
    • Refactor Ogmios context ProtocolParameter instantiation.
    • Adding missing ProtocolParameter.min_pool_cost for Blockfrost context
  • NativeScript
    • from_dict() method used to return either List or NativeScript instance depending on top_level boolean field. Removed this ambiguity by pulling out List generating logic into a separate helper method.
    • Adding a new testcase to ensure nested native scripts are parsed correctly

Minor Updates

  • base.py and blockfrost.py are included in mypy analysis

@daehan-koreapool daehan-koreapool marked this pull request as ready for review November 4, 2022 20:49
pycardano/types.py Outdated Show resolved Hide resolved
pycardano/backend/blockfrost.py Show resolved Hide resolved
pycardano/types.py Outdated Show resolved Hide resolved
pycardano/types.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@cffls cffls left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation regarding JSON, I just learnt a new thing :) The new naming looks good to me.

pycardano/backend/blockfrost.py Show resolved Hide resolved
@daehan-koreapool
Copy link
Contributor Author

Hi @cffls
Please merge this one if everything looks good from your perspective.

@cffls cffls merged commit 7787695 into Python-Cardano:main Nov 7, 2022
@cffls
Copy link
Collaborator

cffls commented Nov 7, 2022

I thought you had permission to merge. Let me double check. Thanks for the reminder.

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