Skip to content
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

Escaped OpenSCAD identifiers don't get exposed (because a single _ makes them private) #17

Open
jeff-dh opened this issue Mar 20, 2023 · 2 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@jeff-dh
Copy link
Owner

jeff-dh commented Mar 20, 2023

OpenSCAD allows identifiers which are "illegal" python identifiers. For example $fn, import, [MCAD.]2Dshapes.

The cuurent solution to this problem is that all "illegal" identifiers (either python keywords or starting with $ or a digit) get escaped. The escape mechnism prepends a single underscore (e.g. $fn -> _fn, import -> _import, MCAD._2Dshapes). This makes them "legal" python identifiers and everything seemed to be fine.

Buuuuut..... it turned out that the prepending underscore makes objects private in python and private objects don't get exported / imported by default. The result is, that from solid2 import * does -- for example -- not import _import even though it's there.

Atm if you want to use such a entity you have to explicitly import it:

from solid2.core.builtins.builtin_primitives import _import
_import('path/to/my.stl')

I don't have any solution for this issue (yet).

We need to prepend something (because of for example 2Dshapes) and I don't like to prepend sp_ or similar. Furthermore I don't want to make breaking changes again to fix this issue.

So I'm sorry for this bad decision I made some time ago, but that's life.

If anyone has any ideas, let me know.

@mingmingrr
Copy link

What about using an explicit import list? Just include it like __all__ = ('_import', 'resize', ...)
https://docs.python.org/3.12/tutorial/modules.html#importing-from-a-package

@jeff-dh
Copy link
Owner Author

jeff-dh commented Nov 10, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants