-
Notifications
You must be signed in to change notification settings - Fork 97
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
Fixes+silences type errors in models #155
Conversation
@@ -17,4 +17,4 @@ class IssuedCurrencyAmount(IssuedCurrency): | |||
See https://xrpl.org/currency-formats.html#issued-currency-amounts. | |||
""" | |||
|
|||
value: str = REQUIRED | |||
value: str = REQUIRED # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this causes a type error because the type of value
is a str
, but the default value is REQUIRED
(an object
). i tried a couple patterns but ran into the issue that the generated getter has a type of Union[<intended type>, object]
which means that at call sites, you have to narrow the type...and we don't want to expose this to callers anyhow
this will likely require a deeper refactor - i could imagine this being implemented as a list of required attributes or a few other ways, although my understanding is that this is a tricky part of dataclass subclassing. as such, i opted for # type: ignore
, as this preserves the type of the getter. not ideal, but don't think i'll have the time to go deeper so i did this everywhere in models
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually i think this is the optimal solution. value = REQUIRED
should be a type error in all cases because if a value = REQUIRED
then an error will be thrown
@@ -80,28 +80,28 @@ def _get_errors(self: PathStep) -> Dict[str, str]: | |||
|
|||
def _get_account_error(self: PathStep) -> Optional[str]: | |||
if self.account is None: | |||
return | |||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for Optional
return types, mypy
by default requires you to return None
instead of having an empty return. this seems like a stylistic choice to me, but opted to just make it pass the default settings to simplify configuration
if we want, we can enable a flag (warn_no_return
) in the config to make this work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine w/ this
You will probs need to do more once #131 is merged in |
sure thing! |
High Level Overview of Change
Some were fixable, others were faster to silence. Comments inline
After this, there are 3 type errors left in all of
xrpl
!Context of Change
Needed so we can use
mypy
onxrpl
Type of Change
Before / After
mypy
returns only 3 errors inxrpl
Test Plan
CI
poetry run mypy --strict xrpl
3 errors should be returned: