Giter VIP home page Giter VIP logo

Comments (3)

erictraut avatar erictraut commented on June 8, 2024

Pyright (the type checker that underlies pylance) is working as intended here. These symbols are not referenced anywhere in the file. You appear to have enabled the reportUnusedImport diagnostic error, which is off by default. When you enable this check, pyright will report an error if your file includes an imported symbol that is not used anywhere within the module and is not re-exported to other modules. In your case, I suspect you intend for these symbols to be re-exported to other modules. By default, symbols imported into a module are assumed to be private (internal) to that module. If you intend to re-export them to other modules, you need to use one of the techniques documented here. You can either include them in an __all__ or use a redundant form of import (for example, from x import y as y). This convention was established in PEP 484 for stub files, but the typing community has since adopted it for ".py" files as well.

If you don't want pyright to generate an error for unreferenced imports, you can choose to disable the reportUnusedImport in your project or on a per-file basis using a # pyright: reportUnusedImport=false at the top of the file.

from pylance-release.

ibobak avatar ibobak commented on June 8, 2024

@erictraut, thank you very much for your answer. Yes, you are right: they are not referenced in the file.
However, this file __init__.py means that this is a package, which later will be used by other modules. In my case, I am writing

from spark_framework import *

from other parts of the code, and due to this import of functions that is surrounded by red rectangle on my screenshot, they are imported fine.

However, it looks like Pylance doesn't recognize it to be in the __init__.py and doesn't get the real intention.

from pylance-release.

debonte avatar debonte commented on June 8, 2024

However, this file __init__.py means that this is a package, which later will be used by other modules.

As Eric mentioned above, if you want to re-export these symbols from this module (and you want a static type checker to understand that that is your intention) you'll either need to include them in an __all__ or use a redundant import form (from x import y as y).

I've copied that part of his response here:

By default, symbols imported into a module are assumed to be private (internal) to that module. If you intend to re-export them to other modules, you need to use one of the techniques documented here. You can either include them in an __all__ or use a redundant form of import (for example, from x import y as y). This convention was established in PEP 484 for stub files, but the typing community has since adopted it for ".py" files as well.

from pylance-release.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.