Skip to content

Add unbounded pointer depth in pure Python 3.7+ - #2571

Open
kne42 wants to merge 6 commits into
cython:masterfrom
kne42:pure-py-unbounded-pointer-depth
Open

kne42 wants to merge 6 commits into
cython:masterfrom
kne42:pure-py-unbounded-pointer-depth

Conversation

@kne42

@kne42 kne42 commented Aug 22, 2018

Copy link
Copy Markdown

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.

Comment thread Cython/Shadow.py Resolved
Comment thread Cython/Shadow.py Outdated
depth = len(match.group(1))
type = match.group(2)

if type in int_types + float_types + complex_types + other_types:

Copy link
Copy Markdown
Contributor

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.

@scoder scoder Aug 25, 2018 •

Copy link
Copy Markdown
Contributor

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.

@scoder

scoder commented Aug 25, 2018

Copy link
Copy Markdown
Contributor

BTW, the fact that travis is unhappy is unrelated to this PR. Would be nice if you could rebase it on latest master.

@scoder

scoder commented Aug 31, 2018

Copy link
Copy Markdown
Contributor

Any update on this?

@kne42

kne42 commented Aug 31, 2018 via email

Copy link
Copy Markdown
Author

@scoder

scoder commented Aug 31, 2018

Copy link
Copy Markdown
Contributor

All fine, no rush, just wanted to check back.
Yep, runnable tests go into tests/run/. Specifically, the pure* tests would be relevant examples here since they are executed in both Cython and Python. You can exclude older Python versions from running the pure Python tests by adding a pure3.7 tag at the top, which also suggests that this would best be a test on its own, just name it pure_py37.py then.

Comment thread Cython/Shadow.py Resolved
Comment thread tests/run/pure_py37.py Resolved
Comment thread tests/run/pure_py37.py Outdated


def test_module_getattr_pointers:
cython.p_int

Copy link
Copy Markdown
Contributor

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. :)

@HSR05

HSR05 commented Mar 19, 2019

Copy link
Copy Markdown

@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. 👍

@TeamSpen210

Copy link
Copy Markdown
Contributor

Instead of using lru_cache, you could just add the constructed pointers to the global namespace. That way future lookups will grab the new attribute and bypass __getattr__ entirely.

@scoder

scoder commented Mar 24, 2019

Copy link
Copy Markdown
Contributor

@TeamSpen210, sounds good.
@HSR05, the test needs fixing and the implementation should work with Py2.7.

Comment thread tests/run/pure_py37.py Resolved
Comment thread tests/run/pure_py37.py Resolved
Comment thread tests/run/pure_py37.py Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants