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

Logging exceptions from Literal value converters #1944

Merged
merged 1 commit into from
May 21, 2022

Conversation

mwatts15
Copy link
Contributor

@mwatts15 mwatts15 commented May 15, 2022

Summary of changes

Adds logging at warning level for exceptions raised when trying to convert a Literal's lexical form into Python-value space. Also refactored to not have convFunc be a boolean -- I think it should resolve the type-checking issue , but I don't know how to run the type checker.

Checklist

  • Checked that there aren't other open pull requests for
    the same change.
  • Added tests for any changes that have a runtime impact.
  • Checked that all tests and type checking passes.
  • For changes that have a potential impact on users of this project:
    • Updated relevant documentation to avoid inaccuracies.
    • Considered adding additional documentation.
    • Considered adding an example in ./examples for new features.
    • Considered updating our changelog (CHANGELOG.md).
  • Considered granting push permissions to the PR branch,
    so maintainers can fix minor issues and keep your PR up to date.

@mwatts15 mwatts15 force-pushed the master branch 3 times, most recently from b351404 to 0cd7713 Compare May 15, 2022 16:33
@aucampia
Copy link
Member

aucampia commented May 15, 2022

Some options for running type checking:

With docker compose:

docker compose build
docker compose run --rm devcontainer mypy --show-error-context --show-error-codes

Or:

docker compose build
docker compose run --rm devcontainer task validate:static

With tox - this will run mypy and unit tests after:

tox -e py37

With go-task in a virtual environment:

task WITH_VENV=1 venv:install validate:static

rdflib/term.py Outdated Show resolved Hide resolved
@mwatts15 mwatts15 force-pushed the master branch 2 times, most recently from bd797e6 to 1397afd Compare May 15, 2022 17:08
@mwatts15
Copy link
Contributor Author

@aucampia what's the policy on updating function/variable names per the "extra-tasks" job? They're pre-existing names, so I didn't see fit to update them.

@coveralls
Copy link

coveralls commented May 15, 2022

Coverage Status

Coverage increased (+0.006%) to 88.437% when pulling bb152a7 on mwatts15:master into ba855c2 on RDFLib:master.

@aucampia
Copy link
Member

aucampia commented May 15, 2022

@aucampia what's the policy on updating function/variable names per the "extra-tasks" job? They're pre-existing names, so I didn't see fit to update them.

It is okay if you don't for now, flakeheaven is the best option we have for gradually getting the codebase to pass with flake8, it is not perfect though, as the baseline kind of gets confused when a file is edited, so sometimes you get errors like you saw now. I will fix them after merging, the most important thing is that we want to catch new code that causes flake8 errors.

That is also why I made it report errors separately.

@mwatts15
Copy link
Contributor Author

win 3.10 failure is an unrelated socket error. could someone re-run?

@aucampia
Copy link
Member

win 3.10 failure is an unrelated socket error. could someone re-run?

Will do, just waiting for others to complete.

@sonarcloud
Copy link

sonarcloud bot commented May 15, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

aucampia added a commit to aucampia/rdflib that referenced this pull request May 16, 2022
This patch setups up some flake8 ignores for names that will come up
more in the future now that we have flakehell running.

One case where this is relevant:
- RDFLib#1944
aucampia added a commit to aucampia/rdflib that referenced this pull request May 16, 2022
This patch setups up some flake8 ignores for names that will come up
more in the future now that we have flakehell running.

One case where this is relevant:
- RDFLib#1944
aucampia added a commit to aucampia/rdflib that referenced this pull request May 16, 2022
This is mainly to address issues experienced with flake8 in
RDFLib#1944
aucampia added a commit that referenced this pull request May 16, 2022
This patch setups up some flake8 ignores for names that will come up
more in the future now that we have flakehell running.

One case where this is relevant:
- #1944
aucampia added a commit that referenced this pull request May 16, 2022
This is mainly to address issues experienced with flake8 in
#1944
@mwatts15 mwatts15 force-pushed the master branch 2 times, most recently from 48003ba to 330e8ef Compare May 20, 2022 02:16
- Also, adding a function to reset bindings so tests are less
  order-dependent
Copy link
Member

@aucampia aucampia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your change looks good, I'm a bit on the fence of using logging.warning though, it has the benefit over warnings.warn that you can see the stack trace, but it has the downside that it is less easy for users to handle programmatically.

The rest of the change makes some much needed improvement.

On a related note, you may be interested in the recently added https://rdflib.readthedocs.io/en/latest/apidocs/rdflib.html#rdflib.term.Literal.ill_formed

Which is basically what this warning will be for:

https://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal

Otherwise, the literal is ill-typed and no literal value can be associated with the literal. Such a case produces a semantic inconsistency but is not syntactically ill-formed. Implementations must accept ill-typed literals and produce RDF graphs from them. Implementations may produce warnings when encountering ill-typed literals.

@aucampia aucampia requested a review from a team May 20, 2022 20:32
@mwatts15
Copy link
Contributor Author

@aucampia thanks. I hit this because I didn't have html5lib installed and parsing for the HTML literal failed (probably should have mentioned in the description...)

Regarding warnings vs logging, main thing I wanted was a stack trace. I tend to see logs from other modules even when I don't see warnings -- not exactly conclusive, but it's pretty consistent for the applications I've worked on.

@aucampia
Copy link
Member

Regarding warnings vs logging, main thing I wanted was a stack trace. I tend to see logs from other modules even when I don't see warnings -- not exactly conclusive, but it's pretty consistent for the applications I've worked on.

I think this is reasonable, without a stack trace the warnings are of limited use, and while getting stack traces from warnings.warn is technically possible, it certainly is not convenient.

@aucampia aucampia merged commit a24586a into RDFLib:master May 21, 2022
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

Successfully merging this pull request may close these issues.

None yet

3 participants