Recommended way to suppress "method overwritten" warnings


#1

Hello,

Some time ago Julia introduced warnings for re-defining methods. This kind of created havoc in my work because what I do all day is

  1. Edit Julia file.
  2. include(“myfile.jl”)
  3. GOTO 1.

So every time I edit my file I’d get a page of warnings. Being informed that my methods have been redefined is not helpful, since that is exactly what I am trying to do. I’m developing + testing. At the time a kind soul produced a module called ClobberingReload that allowed me to get back to work. The big downside of that module is that it suppresses legitimate warnings too.

Over time I changed the way I write my Julia scripts to avoid using functions at all, so I could get real errors without the noise from the “method overwritten” warnings. Of course, this is a horrible solution. The idea of being pushed by the language warnings to avoid using functions is slightly horrifying.

In some cases it just wasn’t viable to avoid functions. So I was forced to change my workflow to:

  1. Edit file.
  2. Exit Julia.
  3. Start Julia. …
  4. include(“myfile.jl”)
  5. GOTO 1

This of course created a big delay in my workflow, but some times it was better than not using functions at all, or using functions but suppressing all errors.

Anyway, that was some time ago. I am now writing with the hope that a better solution has appeared. I have searched through the forums and I have found this package:

This might be a bit more elegant than ClobberingReload, but it doesn’t help with the underlying issue that it suppresses everything to STDOUT, and not just the “method overwritten” warnings.

Is anyone aware of a more recent alternative that would allow me to suppress the “method overwritten” without suppressing other errors? I would really like to go back to coding sensibly. I want to use functions to organize my code, and I want to be informed about syntax errors and the like, without having to reload Julia after every edit, or having Julia complain about every function in my file.

Thank you for your help.

Best wishes,
Daniel.


#2

Method overwrites in Main no longer warn. Putting the code you include into a module will give you only one redefinition warning (the module itself).


#3

Wow. That is excellent news. Thank you so much. So I’ll just upgrade Julia then.

Thanks!


#4

ClobberingReload author here. Can you give an example of suppressed legitimate warning? In theory, ClobberingReload.sinclude should only filter out warnings that match one of these regexes

redefinition_regexes =
    [r"WARNING\: Method definition .* in module .* at .* overwritten at .*\n",
     r"WARNING\: Method definition .* in module .* overwritten\.\n",
     r"WARNING\: replacing docs for .*\n",
     # 0.6 updated its doc warnings with color. Looks like this:
     # \e[1m\e[33mWARNING: \e[39m\e[22m\e[33mreplacing
     r".*WARNING: .*replacing docs for .*\n",
     r"WARNING\: redefining constant .*\n"]

but I suck at regex writing, so it might well filter out some legitimate warnings, too. Suggestions welcome.


#5

kristoffer: It looks like, as of 0.5.2, method overwrites in Main do give warnings:

$ cat test.jl 
function foo(a,b)
	return a + b
end
$ ~/.local/bin/julia 
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.5.2 (2017-05-06 16:34 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-pc-linux-gnu

julia> include("test.jl")
foo (generic function with 1 method)

julia> include("test.jl")
WARNING: Method definition foo(Any, Any) in module Main at /home/daniel/test.jl:2 overwritten at /home/daniel/test.jl:2.
foo (generic function with 1 method)

julia> include("test.jl")
WARNING: Method definition foo(Any, Any) in module Main at /home/daniel/test.jl:2 overwritten at /home/daniel/test.jl:2.
foo (generic function with 1 method)

Help?

Daniel.


#6

cstjean: Hello. Thanks for making ClobberingReload. Oh, I can’t think of an example and now that you say that it shouldn’t suppress legitimate warnings I’m wondering if perhaps I have misunderstood ClobberingReload this whole time.


#7

He was referring to Julia 0.6, which is in the release candidate phase.


#8

How have I only just discovered this?? WOW. Thanks!!


#9

Ah. Thanks! Yeah, now it works.


#10

This is a slightly dangerous workflow. If you accidentally remove a method definition, your code will appear to still work until you restart Julia. So I wouldn’t recommend going back to this, even if you find a way of suppressing warnings.

What I do is:

  1. Edit Julia Files
  2. Pkg.test(“Mypackage”)
  3. GOTO 1

Pkg.test starts up a new Julia process, so there are never any “method overwritten” warnings. (Unless, of course, you accidentally define the same method twice.)


#11

If your package is a bit heavy, it can be annoying to wait for the package to load in the new process if you are developing it interactively.


#12

But I am not writing a Julia package. I use Julia as an interactive data-analysis tool. I use it mostly for plotting and post-processing simulation data. I write small programs that load heavy modules like PyPlot and often some of the statistical modules too. It makes no sense to constantly load and reload Julia and all those modules just to fiddle with the line thickness or colours of a plot. Nor is there much risk that I accidentally delete a method.


#13

Just use anonymous functions? There’s no performance loss, and the syntax is very similar.


#14

As others have noted, the issue is resolved in 0.6.0-rc2. I’m using it right now and I’m very happy. But to answer your question, I guess that if the function is a one-liner I could use anonymous functions.


#15

Or use the multiline version?

f = function (t,u)
 t*u
end