Code Monkey home page Code Monkey logo

Comments (5)

flyx avatar flyx commented on July 24, 2024

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 YamlSerializationErrors. 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.

jfilby avatar jfilby commented on July 24, 2024

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.

flyx avatar flyx commented on July 24, 2024

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.

flyx avatar flyx commented on July 24, 2024

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.

jfilby avatar jfilby commented on July 24, 2024

It seems hints can be silenced with pragmas:

  {.hint[XCannotRaiseY]: off.}

from nimyaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.