You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Repository navigation
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
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:
just parse and add typings to analysis queue
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.
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).
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.
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.
Activity
MikhailArkhipov commentedon Oct 24, 2018
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.
lostmsu commentedon Oct 24, 2018
Mikhail Arkhipov (@MikhailArkhipov) but which one is the correct way? And how do I ensure, that it is even loaded?
lostmsu commentedon Oct 29, 2018
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 anddef foo(bar: int) -> int: ...in a.pyi, analysis ofbarin a.py will give an emptyAnalysisSet, but forb = foo(x)in b.py, it will deducebto beintorNone(because of the original declaration).lostmsu commentedon Oct 29, 2018
Started working on this as a feature here: https://github.com/losttech/PLS/tree/features/AlongsideAnnotations
So far, added parallel annotations AST to
AnalysisUnits, andProjectEntry. With this change, it can take annotations file inAddModule, and let user supply its Tree toIPythonParse. The tree will even be used in multiple places inFunctionInfoandFunctionAnalysisUnit, 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
DDGhave 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.
MikhailArkhipov commentedon Oct 29, 2018
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.
MikhailArkhipov commentedon Feb 4, 2019
We are doing major rework of the analysis engine and #546 supports them.