Skip to content
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

None link title assert hit #326

Open
equaeghe opened this issue Jun 15, 2020 · 10 comments
Open

None link title assert hit #326

equaeghe opened this issue Jun 15, 2020 · 10 comments

Comments

@equaeghe
Copy link

equaeghe commented Jun 15, 2020

There is the following in the code:

assert link.attrs["title"] is not None

Of course someone managed to produce html with links of the form <a title href="example.org">…</a> that trigger this assert. I think better than having the assert would be to replace

if "title" in link.attrs:

with

link_attrs_title = link.attrs.get("title", None)
if link_attrs_title is not None:

N.B.: The same type of pattern fixable in the way can be found on three other occasions:

@Alir3z4
Copy link
Owner

Alir3z4 commented Jun 15, 2020

Thanks for pointing these out.

Would like to know what @jdufresne thinks on this as well.

@equaeghe A pull request that fixes these is welcome.

@equaeghe
Copy link
Author

@equaeghe A pull request that fixes these is welcome.

OK, see #327. It seems there were some problems detected by the CI, but it wasn't really clear to me what the issue was. I fixed some style issues that were found, getting one extra test to be successful. But for the others, I'll need guidance. (Are they even all due to my changes?)

@equaeghe
Copy link
Author

Did you have time to look at my pull request. I again hit an issue fixed by it. Namely, someone managed to put a naked alt in <img … alt …>, which causes alt=None, which causes an exception, because alt is assumed to be a str or bytes.

@jdufresne
Copy link
Collaborator

Would like to know what @jdufresne thinks on this as well.

The general idea makes sense to me once the CI issues are hammered out.

@equaeghe
Copy link
Author

The general idea makes sense to me once the CI issues are hammered out.

I'll have a look at them again. I think I now understand better how the CI works and where to find the errors.

@equaeghe
Copy link
Author

equaeghe commented Sep 11, 2020

I'll have a look at them again. I think I now understand better how the CI works and where to find the errors.

I managed to eliminate all but one of the issues:

https://travis-ci.org/github/Alir3z4/html2text/jobs/726262620

I need assistance with this one @Alir3z4 @jdufresne .

@equaeghe
Copy link
Author

I tried again, but am still hitting an issue I can't seem to solve:

https://travis-ci.org/github/Alir3z4/html2text/jobs/737085613

I really need assistance with this one @Alir3z4 @jdufresne .

@Alir3z4
Copy link
Owner

Alir3z4 commented Oct 19, 2020

Sorry, I missed this

The error is coming from mypy

html2text/__init__.py:540: error: Incompatible types in assignment (expression has type "Optional[str]", variable has type "str")
Found 1 error in 1 file (checked 7 source files)
ERROR: InvocationError for command /home/travis/build/Alir3z4/html2text/.tox/mypy/bin/mypy --strict html2text (exited with code 1)

Seems to be type issues on

html2text/__init__.py:540: error: Incompatible types in assignment (expression has type "Optional[str]", variable has type "str")

@equaeghe
Copy link
Author

equaeghe commented Oct 19, 2020

Seems to be type issues on

html2text/__init__.py:540: error: Incompatible types in assignment (expression has type "Optional[str]", variable has type "str")

Ah, now I get it! Mypy does not infer that attrs.get("href", "") cannot be None. I changed it to attrs.get("href") or "" to convince Mypy. (Bit of a shame, the former seems a more proper approach.) Now that test is passed as well. There's just the inclomplete coverage, but I have the impression that is not due to my patch.

Can you check if you can merge the pull request?

@equaeghe
Copy link
Author

@jdufresne , @Alir3z4: Bump.

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

3 participants