Closed abadfox233 closed 9 months ago
Thanks @abadfox233! This looks great at a glance. Will get hands on with it soon.
Did you come across any limitations or issues with the approach in your testing so far?
It would be good to add some unit tests as we get closer to merging this.
Thank you for your feedback! I've gone ahead and added some unit tests as suggested. These tests cover various scenarios and should help ensure the reliability of the code. If there are specific areas you'd like me to focus on or any further suggestions, please let me know. I'm committed to enhancing the quality of the codebase.
This is working well. One case we should consider is importing from built-in modules. We should probably make this work, for example:
>>> from math import min
module not found: math
>>> math.min
builtin(min)
We could also add this in follow up work.
Otherwise this seems to match what you'd expect coming from Python, which is good.
This enhancement introduces support for the
from
and askeywords
within the Risor compiler, extending its capabilities.New Keywords:
FROM
andAS
Syntax Enhancement
: Thefrom
keyword now supports one or more identifiers after it, similar toa.b.c
. Conversely, theimport
keyword can only be followed by a single identifier. Theas
keyword becomes optional when renaming statements.Compiler Enhancement: New Opcode
FromImport
FromImport
) has been added to the compiler section. This enables the recognition and execution of the enhanced import functionality.Virtual Machine Implementation
from a.b.c import d
, the virtual machine attempts to import thea.b.c.d
module.Should the initial import fail, the system then tries to import variables within the module. For example, with
from a.b.c import d
, the virtual machine tries to import thea.b.c
module and subsequently imports the global variabled
from thec
module.Similar to Python, both imported modules and variables are set as constants after the import process.
This enhancement expands Risor's functionality to provide more flexible and comprehensive import statements, resembling Python's behavior while maintaining consistency within the Risor environment.