Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google sync #1040

Merged
merged 14 commits into from Nov 2, 2021
Merged

Google sync #1040

merged 14 commits into from Nov 2, 2021

Commits on Nov 2, 2021

  1. Add test base support for multi-file tests.

    Allows setting up a dependency tree before checking a file. Python files in the
    dependency tree are analysed in order, and the corresponding pyi files
    generated. The pythonpath for all files is set to the root of the dependency tree.
    
    Also converts one test file as a more extended test of the new functionality.
    
    PiperOrigin-RevId: 406256121
    martindemello authored and rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    9bc3b77 View commit details
    Browse the repository at this point in the history
  2. Fix a bug where Errorlog.copy_from() duplicated error details.

    Error.message contains Error._message, _details, and _traceback combined.
    So copy_from() passing in one error's message attribute as another's _message
    attribute caused a lot of information to be duplicated.
    
    PiperOrigin-RevId: 406272568
    rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    1907505 View commit details
    Browse the repository at this point in the history
  3. Remove a couple of # pytype: skip-file directives.

    The skip in overlays/typing_overlay.py was only needed until the
    typed_ast-based pyi parser went live, which happened months ago.
    
    Once a type annotation is added to the long list in pytd/slots.py, pytype
    analysis completes in a negligible amount of time.
    
    PiperOrigin-RevId: 406371373
    rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    6d19c17 View commit details
    Browse the repository at this point in the history
  4. Fix some issues with handling module aliases.

    Such aliases aren't currently common enough for this to be a problem, but an
    upcoming bug fix that adds a bunch of aliases exposes these issues:
    * In LateType resolution, we need to first check if the entire late type is a
      module name before assuming it's a module attribute.
    * convert._create_module needs to strip only the module prefix; taking off
      everything before the last dotted part is wrong for nested classes.
    * The pyi parser shouldn't allow imports like 'from x import typing' to change
      the meaning of 'from typing import ...'.
    * The pyi parser was rewriting __builtin__ to builtins too aggressively; we
      only want to get rid of imports like "import __builtin__"; lines like "import
      builtins as __builtin__" should not be changed.
    * The pytd printer needs to handle the case when it is passed a partially
      resolved ast in which modules are still represented as NamedType, not Module.
    * Also in the pytd printer, we were accidentally outputting "from x import y as
      y" when we meant to just output "from x import y".
    * serialize_ast needs to undo the pytd printer's application of module aliases.
      (It would be better if serialize_ast could just use the existing ast rather
      than printing and reparsing it, but fixing that is a much bigger endeavor.)
    
    PiperOrigin-RevId: 406413484
    rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    147e3f2 View commit details
    Browse the repository at this point in the history
  5. Support a [not-supported-yet] case in a generic class TypeVar renamin…

    …g check.
    
    We have some logic that checks whether a TypeVar rename is ok, but it would
    emit [not-supported-yet] when trying to compare two bounded/constrained
    TypeVars against each other. The matcher is able to handle this case now, so do
    the comparison instead of complaining.
    
    PiperOrigin-RevId: 406424691
    rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    55772ea View commit details
    Browse the repository at this point in the history
  6. Try again to fix Coverage timeout.

    pytype/pyi:parser_test is still timing out. It seems to be a single test in
    particular that's very slow, so pulling that test out into its own file to
    ensure that nothing else gets put into the same shard as it seems to work.
    
    PiperOrigin-RevId: 406433991
    rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    1978155 View commit details
    Browse the repository at this point in the history
  7. Update comments about overwritten methods.

    The vm subclass now lives in tracer_vm.py, not analyze.py.
    
    PiperOrigin-RevId: 406867564
    Solumin authored and rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    4849e94 View commit details
    Browse the repository at this point in the history
  8. Add __init__ attributes to canonical enum members.

    This kicks in whenever an enum class has its own `__init__` or `__new__` that adds attributes to members, and that enum is used in an annotation or other context that causes a canonical member to be created.
    
    PiperOrigin-RevId: 406868258
    Solumin authored and rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    dff7917 View commit details
    Browse the repository at this point in the history
  9. Fix a couple more pyi import bugs.

    * Recognize LateTypes as modules in the pytd printer. Otherwise, it's
      inconsistent whether an aliased import gets printed as an import or an alias.
    * Also in the pytd printer, add a heuristic for figuring out which prefix of a
      dotted NamedType is the module name. If we don't do this, we generate illegal
      imports containing class names for pb2 nested classes.
    * Fix a bug where pytype crashed on an empty Awaitable type. Improving pyi
      output exposes this bug by precisely typing code in which types were
      previously all Any.
    
    PiperOrigin-RevId: 406869267
    rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    758e242 View commit details
    Browse the repository at this point in the history
  10. Add a feature flag, --gen-stub-imports, to improve pyi import handling.

    Currently, pytype adds "x: module" constants to pyi files, and all attributes
    on builtins.module are typed as Any, so accessing whatever_module.x.attribute
    always produces Any. This is fixed by instead adding "import x" statements and
    changing the pyi parser to always generate aliases for import statements.
    
    This is a very large change because of all the changes to test output and the
    places we need to plumb through --gen-stub-imports so that the pyi parser sees
    it. The actually interesting changes are in:
    * pytype/output.py
    * pytype/pyi/modules.py
    * pytype/pytd/printer.py
    * pytype/pytd/pytd_visitors.py
    
    PiperOrigin-RevId: 406940492
    rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    d97641f View commit details
    Browse the repository at this point in the history
  11. Fix a crash caused by EnumInstance.instantiate() calling itself.

    PiperOrigin-RevId: 407145181
    rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    c0ab8a9 View commit details
    Browse the repository at this point in the history
  12. Add a bit more support for PEP 612 in stubs.

    This is to unblock python/typeshed#6221.
    Also see #786.
    
    PiperOrigin-RevId: 407168815
    rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    6e33205 View commit details
    Browse the repository at this point in the history
  13. Add test for circular types in enum instance attributes.

    PiperOrigin-RevId: 407173206
    Solumin authored and rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    03df5c3 View commit details
    Browse the repository at this point in the history
  14. Prepare a PyPI release.

    PiperOrigin-RevId: 407176581
    rchen152 committed Nov 2, 2021
    Configuration menu
    Copy the full SHA
    1cb0647 View commit details
    Browse the repository at this point in the history