Skip to content

Wrong error triggered in calls with keyword arguments #688

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

Closed
pschella opened this issue Feb 21, 2017 · 7 comments
Closed

Wrong error triggered in calls with keyword arguments #688

pschella opened this issue Feb 21, 2017 · 7 comments

Comments

@pschella
Copy link
Contributor

pschella commented Feb 21, 2017

When a class with an overloaded copy constructor:

struct Bla {
    Bla() = default;
    explicit Bla(const Bla &, bool deep=true) { }
    explicit Bla(const Bla &, int i, std::string s="", bool deep=true) { }
};

wrapped as

    py::class_<Bla>(m, "Bla")
        .def(py::init<>())
        .def(py::init<const Bla &, bool>(),
                "other"_a, "deep"_a=true)
        .def(py::init<const Bla &, int, std::string, bool>(),
                "other"_a, "i"_a, "s"_a="", "deep"_a=true);

Is called with:

b = Bla()
c = Bla(b, 1, deep=False)

The error message reads: TypeError: __init__(): got multiple values for argument 'deep'. Which is confusing.

@pschella
Copy link
Contributor Author

It is actually worse than I thought. Not only is the error confusing. It actually shouldn't error at all when the missing argument has a default value. But it does...

@jagerman
Copy link
Member

Hmm, might be related to #643 and/or #634. I'll take a look.

@jagerman
Copy link
Member

(Is this happening with 2.0.1?)

@pschella
Copy link
Contributor Author

It works on 2.0.1.

@pschella
Copy link
Contributor Author

I.e. is broken on master but not on 2.0.1.

@jagerman
Copy link
Member

Bisected to a3a020c (PR #611).

jagerman added a commit to jagerman/pybind11 that referenced this issue Feb 24, 2017
Fixes pybind#688.

My (commented) assumption that such an error is "highly likely to be a
caller mistake" was proven false by pybind#688.
@jagerman
Copy link
Member

I should have known that something I assumed to be "highly likely" would fail before long (see the diff). Fixed in #696.

wjakob pushed a commit that referenced this issue Feb 24, 2017
Fixes #688.

My (commented) assumption that such an error is "highly likely to be a
caller mistake" was proven false by #688.
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

No branches or pull requests

2 participants