Re: How to support annotations for a custom type in a C extension?

2021-09-18 Thread MRAB
On 2021-09-18 16:10, Serhiy Storchaka wrote: 18.09.21 09:40, Marco Sulla пише: Ooook. I have a question. Why is this code not present in dictobject.c? Where are the dict annotations implemented? In dictobject.c. I just had a look at dictobject.c. It too has a cast to PyCFunction. -- http

Re: How to support annotations for a custom type in a C extension?

2021-09-18 Thread MRAB
On 2021-09-18 16:09, Serhiy Storchaka wrote: 18.09.21 03:54, MRAB пише: static PyMethodDef customdict_methods[] = { ...     {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_CLASS | METH_O | METH_COEXIST, PyDoc_STR("See PEP 585")}, ... }; Note the flags: METH_CLASS says that it's a clas

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-18 Thread Chris Angelico
On Sun, Sep 19, 2021 at 11:46 AM Mostowski Collapse wrote: > > Yeah, it seems weak references could indeed spare > me mark_term(). But then I am stil left with sweep_trail(). > I did not yet measure what takes more time mark_term() > or sweep_trail(). The displayed "gc" is the sum of both. > > Fro

Re: How to support annotations for a custom type in a C extension?

2021-09-18 Thread Serhiy Storchaka
18.09.21 09:40, Marco Sulla пише: > Ooook. I have a question. Why is this code not present in > dictobject.c? Where are the dict annotations implemented? In dictobject.c. -- https://mail.python.org/mailman/listinfo/python-list

Re: How to support annotations for a custom type in a C extension?

2021-09-18 Thread Serhiy Storchaka
18.09.21 03:54, MRAB пише: > static PyMethodDef customdict_methods[] = { > ... >     {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_CLASS | > METH_O | METH_COEXIST, PyDoc_STR("See PEP 585")}, > ... > }; > > > Note the flags: METH_CLASS says that it's a class method and > METH_COEXIST sa

Re: How to "cast" an object to a derived class?

2021-09-18 Thread Robert Latest via Python-list
Stefan Ram wrote: > Robert Latest writes: But how can I "promote" a >>given Opaque instance to the derived class? > > Sometimes, one can use containment instead of inheritance. Nah, doesn't work in my case. I'm trying to write a wrapper around xml.etree.ElemenTree and .Element to circu

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-18 Thread Greg Ewing
On 16/09/21 6:13 am, Mostowski Collapse wrote: So in Python I now do the following: peek = kb.get(functor, NotImplemented) if peek is not NotImplemented: If you're able to use None instead of NotImplemented, you could simplify that to peek = kb.get(functor) if peek: ..

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-18 Thread Mostowski Collapse
Yeah, it seems weak references could indeed spare me mark_term(). But then I am stil left with sweep_trail(). I did not yet measure what takes more time mark_term() or sweep_trail(). The displayed "gc" is the sum of both. >From what I have seen, very large trail practically reduced to a zero trail

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-18 Thread Greg Ewing
On 17/09/21 8:41 pm, Mostowski Collapse wrote: Are exceptions blocks in Python cheap or expensive? Are they like in Java, some code annotation, or like in Go programming language pushing some panic handler? They're not free, but they're not hugely expensive either. Don't be afraid to use them w

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-18 Thread Greg Ewing
On 17/09/21 7:56 am, Mostowski Collapse wrote: The trail in Dogelog Runtime is a single linked list:     -->[ A ]-->[ B ]-->[ C ]--> Now if B becomes unused, you need to rewire the trail, it should then look like:     -->[ A ]-->[ C ]--> Python has a way of creating weak references

Re: Question again

2021-09-18 Thread Michael F. Stemper
On 16/09/2021 19.11, Alan Gauld wrote: On 16/09/2021 06:50, af kh wrote: Hello, I was doing some coding on a website called replit I have no idea what that is but... after answering 'no' or 'yes' after the last sentence I wrote, the Python window shut off, That's what you told it to do in

How to "cast" an object to a derived class?

2021-09-18 Thread Robert Latest via Python-list
Hi all, let's assume I'm using a module that defines some class "Opaque" and also a function that creates objects of that type. In my program I subclass that type because I want some extra functionality. But how can I "promote" a given Opaque instance to the derived class? Of course I could just cr

¡¡¡uoɥʇʎꓒ uᴉ ʇxǝʇ uʍoꓷ ǝpᴉsdꓵ ǝʇɐǝɹↃ oʇ ʍoΗ

2021-09-18 Thread Python 4 Fun
How to Create Upside Down text in Python!!! This is a very simple yet very interesting program in python. We are going to make our text, word or string UPSIDE DOWN which will be still readable on phone or desktop if you stand on your head lol. But any ways... lets do a little research first.