How to create a C Extension that uses CPython internals (outside limited API)?

2020-10-21 Thread Marco Sulla
I'm working on a C extension for frozendict. To make it working, I had to:

1. add by hand the whole path of dictobject.c
(/home/marco/sources/cpython/Objects/dictobject.c)
2. add -DPy_BUILD_CORE
3. add the whole path of CPython includes
(/home/marco/sources/cpython/Include and so on)

This works on my machine, but I suspect that nobody will download the whole
CPython code and add the extra CFLAGS only to make it work.

What do I have to do? I have to copy the CPython source code that I need
inside my c extension folder? What if I also want to support CPython from
3.6 to 3.9?
-- 
https://mail.python.org/mailman/listinfo/python-list


How to write differently to remove this type hint in Python 2.7?

2020-10-21 Thread Shaozhong SHI
Is there another way to do this?

def greet(name: str) -> str:
return "Hello, " + name
greet

File "", line 1 def greet(name: str) -> str:
^ SyntaxError: invalid syntax
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to write differently to remove this type hint in Python 2.7?

2020-10-21 Thread Chris Angelico
On Thu, Oct 22, 2020 at 8:26 AM Shaozhong SHI  wrote:
>
> Is there another way to do this?
>
> def greet(name: str) -> str:
> return "Hello, " + name
> greet
>
> File "", line 1 def greet(name: str) -> str:
> ^ SyntaxError: invalid syntax

If you need to support Python 2, don't use annotations. It's that simple. :)

Bear in mind that Python 2 is now extremely old, and is no longer
supported. A much better option is to use a newer interpreter.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to write differently to remove this type hint in Python 2.7?

2020-10-21 Thread Mats Wichmann
On 10/21/20 3:24 PM, Shaozhong SHI wrote:
> Is there another way to do this?
> 
> def greet(name: str) -> str:
> return "Hello, " + name
> greet
> 
> File "", line 1 def greet(name: str) -> str:
> ^ SyntaxError: invalid syntax
> 

The hinting pep PEP (484) has an alternate syntax that doesn't break 2.7.
-- 
https://mail.python.org/mailman/listinfo/python-list