Skip to content

solid2.extensions.bosl2 collides with python builtins #45

Closed

Description

@taliesin
from solid2.extension.bosl2 import *
s = sum([1, 2, 3])
print(type(s))

outputs <class 'solid2.extensions.bosl2.math.sum'>

One can workaround

import solid2.extension.bosl2 as b2

but this is pretty inconvenient.

The bosl2.math functions could check if the passed type is of their concern and forward to the standard functions otherwise?!

Activity

  1. jeff-dh commented on Sep 30, 2023

    @jeff-dh
    Owner
  2. taliesin commented on Oct 1, 2023

    @taliesin
    Author

    BTW 'list' is also hit, where type checking probably won't work.

  3. jeff-dh commented on Oct 1, 2023

    @jeff-dh
    Owner
    >>> from solid2.extensions import bosl2
    >>> set(dir(bosl2)) & set(dir(__builtins__))
    {'all', '__spec__', 'slice', 'complex', 'list', 'sum', '__doc__', 'any', '__name__', '__loader__', 'format', '__package__'}

    so it's all, slice, complex, list, sum, any and format

    Up until now, I think we need to rething importing bosl2 (and maybe solid2 itself). Your "workaround" might be the solution.
    Another solution would be to explicitly import every single entity used from bosl2:

    from solid2.extensions.bosl2 import cuboid

    This seems inpractically but using a lsp this could also be feasible.

  4. jeff-dh commented on Oct 1, 2023

    @jeff-dh
    Owner

    Another solution would be to strip the bosl2 extension:

    >>> from pprint import pprint
    >>> intersect = set(dir(bosl2)) & set(dir(__builtins__))
    >>> modules = set(bosl2.__getattribute__(n).__module__ for n in intersect if not n.startswith("_"))
    >>> pprint(modules)
    {'solid2.extensions.bosl2.lists',
     'solid2.extensions.bosl2.math',
     'solid2.extensions.bosl2.strings',
     'solid2.extensions.bosl2.utility'}

    All these parts of the library sound to me kind of useless in Solidpython anyway, but I'm not sure..... anyway they could be imported explicitly if needed....

  5. taliesin commented on Oct 5, 2023

    @taliesin
    Author

    I think it's probably the best way to import 'as', otherwise you'll end up hunting symbols when bosl2 progresses.
    Some things are a bit opaque though, as there is a openscad cylinder and a bosl2 cylinder, the latter understanding keywords like anchor.

    Probably the solidpython examples should be rewritten avoiding the 'from ... import *' style. This will prevent beginners from stumbling over these kinds of errors. They are not easily tracked for python beginners.

  6. taliesin commented on Oct 6, 2023

    @taliesin
    Author

    Nice work, if the list of imports gets too long, the alternative
    import solid2.extensions.bosl2 as b2
    is acceptable as well and pretty much inline with numpy as np, for instance.

    Thx for the work.

  7. jeff-dh commented on Oct 6, 2023

    @jeff-dh
    Owner

    Hmmm, that was to fast ;)

    I'm still not happy with the collision of the bosl2 namespace and globals()... I'm still thinking about striping the critical parts from the bosl2 extension. So reopen.....

  8. reopened this on Oct 6, 2023
  9. jeff-dh commented on Oct 15, 2023

    @jeff-dh
    Owner

    I striped the math, lists, strings and utility modules from bosl2.std.

    This will be published in a 2.1.0 version with some other backwards compatibility breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions