You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #261 the return types of the load(), load_foreign() and generate() methods in ewatercycle.forcing where removed due to using them in notebooks gave mypy errors. So when using these methods you fall back to dynamically typed code at runtime.
It would be nice if return types could be restored somehow so while coding you can autocomplete attributes of the forcing object without having to have forcing object at runtime.
The text was updated successfully, but these errors were encountered:
Can we state the exact problem? Is it that all these methods generate model-specific <Model>Forcing objects? Somehow all forcing objects inherit from DefaultForcing, so if we could tell mypy that it should check the parent instead of the model-specific object, that might fix it, right?
Yep, generate() returns an unknown sublclass of DefaultForcing while model constructor requires a specific DefaultForcing subcloass.
Also when mypy thinks forcing object is DefaultForcing, you can not use any of specialized attributes of a subclass without mypy complaining or performing casts.
For example:
importewatercycle.forcingimportewatercycle.modelsfromtypingimportcastforcing=ewatercycle.forcing.generate(
target_model='marrmot',
dataset='ERA5',
start_time='2010-01-01T00:00:00Z',
end_time='2010-12-31T00:00:00Z',
shape='Merrimack/Merrimack.shp'
) # :rtype DefaultForcingforcing.forcing_file# does not workmarrmot_forcing=cast(MarrmotForcing, forcing)
marrmot_forcing.forcing_file# worksmodel=ewatercycle.models.MarrmotM14(version="2020.11", forcing: MarrmotForcing=marrmot_forcing)
In #261 the return types of the
load()
,load_foreign()
andgenerate()
methods inewatercycle.forcing
where removed due to using them in notebooks gave mypy errors. So when using these methods you fall back to dynamically typed code at runtime.It would be nice if return types could be restored somehow so while coding you can autocomplete attributes of the forcing object without having to have forcing object at runtime.
The text was updated successfully, but these errors were encountered: