Skip to content

Python: Improve error messages for argument type mismatch #28

@thomastrapp

Description

@thomastrapp

For example, using Python 3.12, Hext 1.0.8:

import hext
rule = hext.Rule("<a href:link/>")
# Error, the argument for extract is of type string:
results = rule.extract("""<a href="b"></a>""")

Produces an unhelpful error message:

Traceback (most recent call last):
  File "/home/dev/issue-27/issue28-example.py", line 4, in <module>
    results = rule.extract("""<a href="b"></a>""")
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dev/issue-27/venv/lib/python3.12/site-packages/hext/__init__.py", line 139, in extract
    return _hext.Rule_extract(self, html, max_searches)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Wrong number or type of arguments for overloaded function 'Rule_extract'.
  Possible C/C++ prototypes are:
    Rule::extract(Html const &,std::uint64_t) const
    Rule::extract(Html const &) const

The error message should explicitly state that the wrong type of argument was passed, and that an hext.Html was expected.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions