question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error with @autoclass concerning default arguments' type

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
smariecommented, Dec 4, 2017

Thanks @Stewori ! I confirm that this fixes the issue.

0reactions
Steworicommented, Nov 20, 2017

Note that pytypes 1.0b3 was released for PyPI yesterday. It contains this bugfix.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found