Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd unbounded pointer depth in pure Python 3.7+ #2571
Conversation
@@ -461,3 +461,16 @@ def threadid(self): | |||
import sys | |||
sys.modules['cython.parallel'] = CythonDotParallel() | |||
del sys | |||
|
|||
|
|||
def __getattr__(name, module=__name__): |
scoder
Aug 23, 2018
Contributor
Nice idea! Worth a docstring, though, to explain what this is used for and why it's done this way.
depth = len(match.group(1)) | ||
type = match.group(2) | ||
|
||
if type in int_types + float_types + complex_types + other_types: |
TeamSpen210
Aug 23, 2018
Contributor
Might it be worth caching this list, or checking each individually? It'll only be used during import yes, but it's better to not be more expensive than necessary.
scoder
Aug 25, 2018
•
Contributor
Agreed. Can be done by assigning the whole concatenation to an additional default argument, for example.
BTW, type
overrides the builtin name, so I'd rather call the variable type_name
.
BTW, the fact that travis is unhappy is unrelated to this PR. Would be nice if you could rebase it on latest master. |
Any update on this? |
@scoder I have been on holiday for the past two weeks with limited access
to my laptop and wifi. I will update the PR as soon as I get back.
In the meantime, I think this should come with a test as well. I presume
that this fits best under tests/run, correct?
…On Fri, Aug 31, 2018 at 10:29 scoder ***@***.***> wrote:
Any update on this?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2571 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/Ab0F0zKTZeKbUOAkg1Thw8DUJKGJxGP6ks5uWPPUgaJpZM4WIbNO>
.
|
All fine, no rush, just wanted to check back. |
@@ -461,3 +461,23 @@ def threadid(self): | |||
import sys | |||
sys.modules['cython.parallel'] = CythonDotParallel() | |||
del sys | |||
|
|||
import functools | |||
@functools.lru_cache() |
scoder
Sep 12, 2018
Contributor
Ah, the fact that the feature is only available in Py3.7+ does not mean that the code will only be used there. This file should stay compatible with Py2.6+ for now, which doesn't have functools.lru_cache
.
import cython | ||
|
||
|
||
def test_module_getattr_pointers: |
|
||
|
||
def test_module_getattr_pointers: | ||
cython.p_int |
scoder
Sep 12, 2018
Contributor
These should be used in a valid context, e.g. use int_ptr: cython.p_int
as a variable declaration. Preferably, also find a way to make actual use of these variables. :)
@scoder I'll try looking into it. Can you give me some guidance on the work thats already done and what needs to be done. I would be really thankful. |
Instead of using |
@TeamSpen210, sounds good. |
Leverages module-level
__getattr__
as introduced in PEP 562 (Python 3.7+) to enable unbounded depth on pointers in interpreted Python based on their names; i.e.from cython import ppppppp_int
will now be valid.