Comments (5)
The raises
annotation on dump()
is not strictly necessary, Nim would calculate it automatically. However, as API provider, I want the compiler to ensure that no other errors can be raised during serialization, therefore I give this explicit error as error that can possibly be raised.
Now dump()
is a generic function, and which represent
function(s) it calls depends on the given type. Some represent
functions actually can raise YamlSerializationError
, others can't. You happen to give a type which does not lead to any possible YamlSerializationError
s. Since generics are handled at compile-time, the compiler knows that no such error can ever be raised, and gives that hint.
However, I cannot remove the YamlSerializationError
annotation because a call with a different type will need it. I don't want to drop the raises
annotation altogether because it prevents me from accidentally introducing exceptions when maintaining this library.
To sum up: The compiler is right with this hint, but there doesn't seem to be a way to get rid of it without harming maintainability.
from nimyaml.
OK, but perhaps it can be hidden with a -d compiler switch? When I scan for warnings it would be useful to ignore this.
from nimyaml.
Hm, I think this can be solved with
{.push hint[XCannotRaiseY]: off.}
…
{.pop.}
around the relevant declarations. Don't have the time to test this right now but I'll do that soon-ish.
from nimyaml.
So… that doesn't work. As explained in this thread, due to lazy compilation, the push/pop pragmas must be around the code that causes the dump
function to compile, which is, due to lazy compilation, the calling code. I imagine you don't want to put that around every call to dump
on your side.
Testing also showed that yours is not the only hint that may potentially be shown, another one is
NimYAML/yaml/serialization.nim:400:44 Hint: 'representObject' cannot raise 'ValueError'
Something should certainly be done about these. My Nim is a bit rusty (not doing anything in Nim but maintaining this lib) but I'd imagine doing something like
when defined(doNimYamlTest):
{.push raises: […].}
# … code …
when defined(doNimYamlTest):
{.pop.}
might work. This would remove the explicit annotations in production while still being able to check their validity during testing. The only question remaining would be how to treat this on the API docs (should they still show the annotation or not?).
This would need a larger refactoring to group all similarly annotated procs together (or put the stuff about around every single one). In case you know a more elegant solution, I'd love to hear it.
from nimyaml.
It seems hints can be silenced with pragmas:
{.hint[XCannotRaiseY]: off.}
from nimyaml.
Related Issues (20)
- Option to Ignore unknown fields HOT 1
- Handle multi-line arrays HOT 2
- Currently Failing Suite Tests HOT 1
- Strings of length >= 80 with a single non-space character serialize to invalid YAML HOT 2
- Comment after block/multi-line text HOT 2
- Future compile-time error in dom.nim HOT 2
- loadDom SIGSEGV: Illegal storage access. HOT 7
- [Documentation] Simple example for loading a simple .yml file? HOT 3
- broken enum HOT 3
- dumping leaves part of string on same line as >- making the file unable to be loaded from HOT 8
- `| >` wrapping functionality can generate invalid YAML HOT 1
- Fails to parse a triple dot in string lit
- defaultVal is not observed on stropped names HOT 2
- Anchor in ignored tag HOT 5
- Feature: Let user choose/disable maximum line length for presentation HOT 4
- BUG: loading zero to unsigned integer generates a YamlConstructionError
- BUG: loading to float32 generates an error HOT 3
- Can't get optional fields to work HOT 3
- ignore pragma doesn't work on nested maps HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nimyaml.