New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unbounded pointer depth in pure Python 3.7+ #2571
base: master
Are you sure you want to change the base?
Conversation
@@ -461,3 +461,16 @@ def threadid(self): | |||
import sys | |||
sys.modules['cython.parallel'] = CythonDotParallel() | |||
del sys | |||
|
|||
|
|||
def __getattr__(name, module=__name__): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Syntax error.
|
||
|
||
def test_module_getattr_pointers: | ||
cython.p_int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.