How to define a Python class in a module with PyCall?

I want to write a Julia module in which I define a Python class using PyCall. Using an example in the README of PyCall, a MWE:

module parent
using PyCall

const pypoly = PyNULL()
function __init__()
    copy!(pypoly, pyimport("numpy.polynomial"))
end

@pydef mutable struct Doubler <: pypoly.Polynomial
    function __init__(self, x=10)
        self.x = x
    end
    my_method(self, arg1::Number) = arg1 + 20
    x2.get(self) = self.x * 2
    function x2.set!(self, new_val)
        self.x = new_val / 2
    end
end

end

Using this module failed with the error message:

ERROR: LoadError: ArgumentError: ref of NULL PyObject
Stacktrace:
 [1] _getproperty
   @ ~/.julia/packages/PyCall/3fwVL/src/PyCall.jl:299 [inlined]
 [2] __getproperty(o::PyCall.PyObject, s::Symbol)
   @ PyCall ~/.julia/packages/PyCall/3fwVL/src/PyCall.jl:306
 [3] getproperty(o::PyCall.PyObject, s::Symbol)
   @ PyCall ~/.julia/packages/PyCall/3fwVL/src/PyCall.jl:312
 [4] top-level scope
   @ ~/.julia/packages/PyCall/3fwVL/src/pyclass.jl:205
 [5] include(fname::String)
   @ Base.MainInclude ./client.jl:451
 [6] top-level scope
   @ REPL[1]:1
in expression starting at ~/Downloads/testmodule.jl:1

I guess the problem was with the part <: pypoly.Polynomial in @pydef during pre-compilation because at that time, pypoly is still null. Is there any way to achieve this? I tried disabling precompilation but still got the error.

You can define the class in __init__ too and copy! it, just like you do for pypoly.