error with @autoclass concerning default arguments' type
See original GitHub issueI would like to provide an example showing how pytypes can be used with autoclass. However the following code fails with a strange error:
from autoclass import autoclass, Boolean
from pytypes import typechecked
from numbers import Real, Integral
from typing import Optional
@typechecked
@autoclass
class HouseConfiguration(object):
def __init__(self,
name: str,
surface: Real,
nb_floors: Optional[Integral] = 1,
with_windows: Boolean = False):
pass
# -- overriden setter for surface for custom validation
@setter_override
def surface(self, surface):
assert surface > 0
self._surface = surface
t = HouseConfiguration('test', 12, 2) # error
The error received is :
Expected: Tuple[str, Real, Union[Integral, NoneType], Boolean]
Received: Tuple[str, int, int, int]
While this works:
t = HouseConfiguration('test', 12, nb_floors=2)
So it seems that this does not have anything to do with autoclass: somehow positional arguments / default values in the constructor signature are not handled properly.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How do I add default parameters to functions when using type ...
I can't find anything in the typing documentation or on a Google search. Edit: I didn't know how default arguments worked in Python,...
Read more >Error with generic argument defaults #3130 - microsoft/pyright
Pyright reports an error when returning an instance from generic type arguments with default values. class Base: pass class Derived(Base): ...
Read more >Template parameters and template arguments
In a function template, there are no restrictions on the parameters that follow a default, and a parameter pack may be followed by...
Read more >sphinx.ext.autodoc – Include documentation from docstrings
The default value is "all" , meaning that types are documented for all parameters and return values, whether they are documented or not....
Read more >Common parameters - CatBoost
Type. float. Default value. The default value is defined automatically for Logloss, MultiClass & RMSE loss functions depending on the number of iterations ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @Stewori ! I confirm that this fixes the issue.
Note that pytypes 1.0b3 was released for PyPI yesterday. It contains this bugfix.