Skip to content

py: rename array module to uarray #4449

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

Closed

Conversation

dpgeorge
Copy link
Member

And provide backwards compatible weak link so that import array still works.

See #4370

@pfalcon
Copy link
Contributor

pfalcon commented Jan 31, 2019

Thanks. But I'm not sure if it's worth to enable weak links in unix port just for one module. How about just to re-add "array" alias name via MICROPY_PORT_BUILTIN_MODULES until the next release?

@dpgeorge
Copy link
Member Author

How about just to re-add "array" alias name via MICROPY_PORT_BUILTIN_MODULES until the next release?

I don't think that will work, in the sense that it will always be found first and so an array.py file could not override it.

But I'm not sure if it's worth to enable weak links in unix port just for one module.

Well, I wanted to enable it anyway, and add many links there, so the unix binary can emulate CPython more closely without needing a set of libraries on the filesystem.

@pfalcon
Copy link
Contributor

pfalcon commented Jan 31, 2019

Well, I wanted to enable it anyway, and add many links there, so the unix binary can emulate CPython more closely without needing a set of libraries on the filesystem.

How about all the concerns that it adds more confusion than benefits?

@dhylands
Copy link
Contributor

I find the fact that it doesn't behave like the bare metal ports to be more confusing than the way it behaves now.

@pfalcon
Copy link
Contributor

pfalcon commented Jan 31, 2019

So, as usual, confusion comes in layers. Baremetal ports behaves confusing by offering fake "CPython compatibility". Then to some people the fact that unix port doesn't fake it is also confusing, and it goes in rounds and in circles.

The well-known solution is to cut solution where it begins. The worst solution is to make confusion all-encompassing and unescapable.

@dpgeorge
Copy link
Member Author

dpgeorge commented Feb 1, 2019

Baremetal ports behaves confusing by offering fake "CPython compatibility".

MicroPython is intended to provide a faithful as possible implementation of Python, with modules included where possible.

The well-known solution is to cut solution where it begins.

So is the proposal to remove weak links altogether and make import array (and all the others like import time) stop working?

@pfalcon
Copy link
Contributor

pfalcon commented Feb 1, 2019

MicroPython is intended to provide a faithful as possible implementation of Python, with modules included where possible.

As you understand, in this case, "as faithful as possible" would be "allowing to implement as complete as possible API of CPython in the obvious way, by clearly separating what's MicroPython API and not hogging namespaces which don't belong to it".

So is the proposal to remove weak links altogether and make import array (and all the others like import time) stop working?

As you very well understand either, I hardly could realistic propose that, even though I definitely try to maintain a view opposing weak links (so the truth was somewhere in the middle). My point would be to try to define well what weak links are. In my view, it is a product-specific feature, offered by vendors of specific products as a feature to their users to smooth the curve of learning "native MicroPython". On the level of the language itself, it's an ugly hack, which despite its good intentions, leads to the opposite effect - people don't learn how to use native MicroPython well, and instead remain in permanent confusion regarding what MicroPython vs CPython are.

Anyway, beyond paradigmatic aspect of it, I have a specific proposal: how about dropping all those growing data structures to maintain, and add following code (under the config option of course):

  • If the import is absolute (should make sure to not apply to package-local imports), if import of "foo" fails, then try to see if there's a builtin module "ufoo", and if there's, import it instead.

Done like that, it should be clear to anyone that it's nothing but a special-purpose hack. Should save some bytes, too.

@pfalcon
Copy link
Contributor

pfalcon commented Feb 8, 2019

Ok, so can we finish with this in obvious least effort/least scope creep way: a) proceed with the rename; b) for ports which already have weak links enabled, add a weak link; c) for ports which don't use weak links, just have 2 entries "array" and "uarray" pointing to the same module.

This will allow to normalize docs, and that's the main driver for the, change, and seeing how to allow to actually override "array" consistently can be dealt with as a next task.

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Oct 22, 2019
dpgeorge added a commit that referenced this pull request Oct 22, 2019
This commit implements automatic module weak links for all built-in
modules, by searching for "ufoo" in the built-in module list if "foo"
cannot be found.  This means that all modules named "ufoo" are always
available as "foo".  Also, a port can no longer add any other weak links,
which makes strict the definition of a weak link.

It saves some code size (about 100-200 bytes) on ports that previously had
lots of weak links.

Some changes from the previous behaviour:
- It doesn't intern the non-u module names (eg "foo" is not interned),
  which saves code size, but will mean that "import foo" creates a new qstr
  (namely "foo") in RAM (unless the importing module is frozen).
- help('modules') no longer lists non-u module names, only the u-variants;
  this reduces duplication in the help listing.

Weak links are effectively the same as having a set of symbolic links on
the filesystem that is searched last.  So an "import foo" will search
built-in modules first, then all paths in sys.path, then weak links last,
importing "ufoo" if it exists.  Thus a file called "foo.py" somewhere in
sys.path will still have precedence over the weak link of "foo" to "ufoo".

See issues: #1740, #4449, #5229, #5241.
dpgeorge added a commit that referenced this pull request Oct 22, 2019
Following the other modules like ustruct, ucollections.

See issues #4370 and #4449.
@dpgeorge
Copy link
Member Author

array was renamed to uarray in 21a6093, docs updated in a2eea57

A weak link is provided from array to uarray so that import array will still work.

@dpgeorge dpgeorge closed this Oct 22, 2019
@dpgeorge dpgeorge deleted the py-array-rename-to-uarray branch October 22, 2019 05:43
alu96 pushed a commit to alu96/micropython that referenced this pull request Mar 23, 2020
This commit implements automatic module weak links for all built-in
modules, by searching for "ufoo" in the built-in module list if "foo"
cannot be found.  This means that all modules named "ufoo" are always
available as "foo".  Also, a port can no longer add any other weak links,
which makes strict the definition of a weak link.

It saves some code size (about 100-200 bytes) on ports that previously had
lots of weak links.

Some changes from the previous behaviour:
- It doesn't intern the non-u module names (eg "foo" is not interned),
  which saves code size, but will mean that "import foo" creates a new qstr
  (namely "foo") in RAM (unless the importing module is frozen).
- help('modules') no longer lists non-u module names, only the u-variants;
  this reduces duplication in the help listing.

Weak links are effectively the same as having a set of symbolic links on
the filesystem that is searched last.  So an "import foo" will search
built-in modules first, then all paths in sys.path, then weak links last,
importing "ufoo" if it exists.  Thus a file called "foo.py" somewhere in
sys.path will still have precedence over the weak link of "foo" to "ufoo".

See issues: micropython#1740, micropython#4449, micropython#5229, micropython#5241.
alu96 pushed a commit to alu96/micropython that referenced this pull request Mar 23, 2020
Following the other modules like ustruct, ucollections.

See issues micropython#4370 and micropython#4449.
c0d3z3r0 pushed a commit to c0d3z3r0/micropython that referenced this pull request Apr 5, 2020
This commit implements automatic module weak links for all built-in
modules, by searching for "ufoo" in the built-in module list if "foo"
cannot be found.  This means that all modules named "ufoo" are always
available as "foo".  Also, a port can no longer add any other weak links,
which makes strict the definition of a weak link.

It saves some code size (about 100-200 bytes) on ports that previously had
lots of weak links.

Some changes from the previous behaviour:
- It doesn't intern the non-u module names (eg "foo" is not interned),
  which saves code size, but will mean that "import foo" creates a new qstr
  (namely "foo") in RAM (unless the importing module is frozen).
- help('modules') no longer lists non-u module names, only the u-variants;
  this reduces duplication in the help listing.

Weak links are effectively the same as having a set of symbolic links on
the filesystem that is searched last.  So an "import foo" will search
built-in modules first, then all paths in sys.path, then weak links last,
importing "ufoo" if it exists.  Thus a file called "foo.py" somewhere in
sys.path will still have precedence over the weak link of "foo" to "ufoo".

See issues: micropython#1740, micropython#4449, micropython#5229, micropython#5241.
tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Mar 22, 2021
adventure together with rotary trinkey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants