question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Investigate Type Annotation

See original GitHub issue

Is your feature request related to a problem? Please describe. I just started exploring pyinfra and so far I like it a lot. I happen to use VSCode with the Pylance plugin. This appears to throw a ton of red squiggles on anything decorated with the @operation decorator if Type Checking Mode is set to basic. The completion/help for any function arguments is also broken. I suspect the issue is related to https://github.com/microsoft/pyright/issues/774, but I’m not sure how to deal with how the @operation decorator adds global arguments.

Describe the solution you’d like I suspect providing type annotations for the entire project is out of scope (for now… 😄 ), but it would be interesting to explore how to better support some basic type annotations. This may be more of a v2 problem though.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Fizzadarcommented, Nov 3, 2022

Typing is now in! Not 100% but mypy is part of CI and types can gradually be introduced. The global operation args are typed.

0reactions
karlicosscommented, Apr 17, 2021

I’ve found lack of types not that bad since there are decent docs and pyinfra seems well tested. But for my own custom deploys I’m more worried about messing them up. For anyone who wants to at least type their own deploys, you can use this trick:

from typing import TypeVar, Callable
F = TypeVar('F', bound=Callable)
if typing.TYPE_CHECKING:
    # this will expose the wrapped function's type to mypy
    def deploy(f: F) -> F:
        pass 
else:
    from pyinfra.api import deploy

Then stuff like this will be type checked:

@deploy
def my_operation(*, arg1: str, arg2: int, **kwargs): 
    ...

You can also probably use it for typing some of pyinfra’s API on ad-hoc basis

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the type annotation to use for a type annotation?
Why am I taking a type annotation as an argument? I have a function that tries to parse a string based on a...
Read more >
Web resources for cell type annotation - 10x Genomics
Here we present two types of web resources for cell type annotation. They are relatively easy to use and do not require advanced...
Read more >
Assessing the type annotation burden - ResearchGate
Type annotations provide a link between program variables and domain-specific types. When combined with a type system, these annotations can ...
Read more >
The Evolution of Type Annotations in Python:An Empirical Study
We study type annotation changes by, at first, investigating how often type annotations are updated at all. To this end, we analyze all...
Read more >
inspect — Inspect live objects — Python 3.11.1 documentation
There are four main kinds of services provided by this module: type checking, ... mapping of parameters names to annotations; "return" key is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found