← 输入框|github.com|刷新
Skip to content

Implement "import A; A.something()" #1809

Open

Description

@certik

Right now the only way is from A import something which works, but we also need to support "import A".

Activity

  1. Thirumalai-Shaktivel commented on May 15, 2023

    @Thirumalai-Shaktivel
    Collaborator

    Can you please share a minimal example?
    This seems to work:

    import a; a.f()

    a.py

    def f():
        print(123)
    $ lpython -I. expr2.py
    123
  2. Smit-create commented on May 15, 2023

    @Smit-create
    Collaborator

    Maybe this is something that's fixed by: #1795?

  3. Thirumalai-Shaktivel commented on May 15, 2023

    @Thirumalai-Shaktivel
    Collaborator

    Yup, might be!

  4. certik commented on May 15, 2023

    @certik
    ContributorAuthor

    Excellent, indeed it works for user code now, I verified it. However, it doesn't work for numpy:

    import numpy
    a: f64[5] = numpy.empty(5)

    gives:

    $ lpython b.py -I.
    semantic error: The symbol 'empty' not found in the module 'numpy'
     --> b.py:2:13
      |
    2 | a: f64[5] = numpy.empty(5)
      |             ^^^^^^^^^^^^^^ 
  5. Smit-create commented on May 15, 2023

    @Smit-create
    Collaborator

    I think, its because we have a hard-coded empty in Call.

    } else if (call_name == "empty") {
    // TODO: check that the `empty` arguments are compatible
    // with the type
    tmp = nullptr;
    return;

  6. certik commented on May 15, 2023

    @certik
    ContributorAuthor

    Yes, it's probably time to fix this.

  7. Smit-create commented on May 16, 2023

    @Smit-create
    Collaborator

    The fix is to add empty function in lpython_intrinsic_numpy.py but that gets tricker when we need robust generics(I didn't try that much with the current structure that we have) since empty takes different argument types like empty(2), empty((2, 3)), empty([2, 3]), etc. and also returns difference types.

  8. certik commented on Jun 6, 2023

    @certik
    ContributorAuthor

    I would support:

    from numpy import empty
    a: f64[5] = empty(5)
    

    and fail on:

    from numpy import sin
    a: f64[5] = empty(5)
    

    And succeed on:

    from numpy import sin
    def empty(n: i32) -> i32:
        return 5
    a: i32 = empty(5)
    
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions