Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Is it possible to use .pyi files alongside analized code? #296

Closed

Description

@lostmsu

I am analyzing a project, that does not have embedded typings, and but there are separate typings for it in .pyi files.

How can I make PythonAnalyzer use those typings?

What I've tried so far:

  1. just parse and add typings to analysis queue
  2. put typings into a separate directory Typings like Typings\mymodule\mysubmodule.pyi, and use PythonAnalysis.SetTypeStubPaths to Typings.

In both cases, when walking mymodule\mysubmodule.py file after analysis, and trying to GetValues(Expression, ...) I get the same values as if there's no matching typings file.

Activity

  1. MikhailArkhipov commented on Oct 24, 2018

    @MikhailArkhipov

    Technically they are used, however, there may be bugs in parsing pyi.
    Related
    #301
    #300
    #254

    Try using pyi with simple syntax first, to be sure basic scenario works.

  2. lostmsu commented on Oct 24, 2018

    @lostmsu
    ContributorAuthor

    Mikhail Arkhipov (@MikhailArkhipov) but which one is the correct way? And how do I ensure, that it is even loaded?

  3. lostmsu commented on Oct 29, 2018

    @lostmsu
    ContributorAuthor

    After playing with it a bit, it seems, that pyi files only work for non-source code modules. For source code, they only have effect on the consumers of the module they are declared for, but not on the module itself.

    e.g. with def foo(bar): ... in a.py and def foo(bar: int) -> int: ... in a.pyi, analysis of bar in a.py will give an empty AnalysisSet, but for b = foo(x) in b.py, it will deduce b to be int or None (because of the original declaration).

  4. lostmsu commented on Oct 29, 2018

    @lostmsu
    ContributorAuthor

    Started working on this as a feature here: https://github.com/losttech/PLS/tree/features/AlongsideAnnotations

    So far, added parallel annotations AST to AnalysisUnits, and ProjectEntry. With this change, it can take annotations file in AddModule, and let user supply its Tree to IPythonParse. The tree will even be used in multiple places in FunctionInfo and FunctionAnalysisUnit, however, all evaluation will happen within the context of the main file, which basically means, that all imports in .pyi will be ignored.

    I'll try to have analyzer walk over annotations, and let DDG have a separate evaluator for them.

    Would be glad to hear some intermediate input, before too much is spent on this feature, and you, guys, don't like the wait its implemented.

  5. MikhailArkhipov commented on Oct 29, 2018

    @MikhailArkhipov

    Correct, they are only used in library analysis since it is too expensive to run full analyzer on such large bodies of code and stub files bring clear benefit.

  6. MikhailArkhipov commented on Feb 4, 2019

    @MikhailArkhipov

    We are doing major rework of the analysis engine and #546 supports them.

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

    questionA question about the LS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions