Mark built-in module as deprecated

M

moerchendiser2k3

Hi,

can anyone give me a hint how to mark a built-in module as deprecated?
So mark via warnings... I create a module with Py_InitModule4.

Thanks in advance!!

Bye, moerchendiser2k3
 
T

Thomas Jollans

Hi,

can anyone give me a hint how to mark a built-in module as deprecated?
So mark via warnings... I create a module with Py_InitModule4.

How are modules ever marked as deprecated? I think all there is to it is
issuing a DeprecationWarning... something like

PyErr_WarnEx(PyExc_DeprecationWarning, "foo deprecated. use fuzz", 1);

maybe.
 
M

moerchendiser2k3

PyErr_WarnEx(PyExc_DeprecationWarning, "foo deprecated. use fuzz",
1);

But where can I write this? With Py_InitModule4 I can just
pass a list of functions but no real execution part which
is executed when a module is imported.
 
T

Thomas Jollans

PyErr_WarnEx(PyExc_DeprecationWarning, "foo deprecated. use fuzz",
1);

But where can I write this? With Py_InitModule4 I can just
pass a list of functions but no real execution part which
is executed when a module is imported.

This is Python 2.x, right? I'm only familiar with Python 3 extension
writing, but there shouldn't have been that much change...

Where do you call the Py_InitModule4? I would have expected you call it
in your initfoo function - which is also a good place to issue a
warning. - the initfoo (or PyInit_foo) function is called when the
module is first imported.
 
M

moerchendiser2k3

Hi, yes, that was my first idea when I just create an
external module. I forgot something to say:

In my case the initfoo() function is called on startup
in my embedding environment, that means I call that
on startup of my main app.

Bye,
moerchendiser2k3
 
T

Thomas Jollans

Hi, yes, that was my first idea when I just create an
external module. I forgot something to say:

In my case the initfoo() function is called on startup
in my embedding environment, that means I call that
on startup of my main app.
ah. In that case, I don't think it's possible to do anything on import -
AFAIK, if the module "foo" is already loaded/initialized, "import foo"
is equivalent to "foo = sys.modules['foo']" and doesn't invoke any
module-specific code...

You could issue a warning on each and every method call in your module,
so that when it's used, the user gets warned. Then you could cache
whether a warning has been issued already in a global static variable or
in module state to be able to only warn once.

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,145
Latest member
web3PRAgeency
Top