Hey <@ULVA73B9P> pylance isn't happy with using su...
# ask-marvin
f
Hey @Marvin pylance isn't happy with using submit() on tasks. I get this linting error
Cannot access attribute "submit" for class "MethodType"
Attribute "submit" is unknown
Is that a know issue, any workaround?
m
thought for 147.1 seconds
Yes, this is a known issue with static type checkers like Pylance when dealing with Prefect's task submission methods. There are a few workarounds you can use: 1. Add a type ignore comment:
Copy code
python
result = task.submit()  # type: ignore
2. Use explicit type annotations with PrefectFuture:
Copy code
python
from prefect.futures import PrefectFuture

result: PrefectFuture = task.submit()
3. If you're using VS Code, you can also add the specific error code to your settings to suppress this particular warning:
Copy code
json
{
    "python.analysis.diagnosticSeverityOverrides": {
        "reportAttributeAccessIssue": "none"
    }
}
The issue occurs because Prefect uses some dynamic method creation that static type checkers have trouble following. The code will work correctly at runtime despite the linting error. If you're working on a larger project and want to maintain strict type checking, I'd recommend using the second approach with explicit type annotations, as it provides the best balance between type safety and code clarity. Remember that while the linter complains, the
.submit()
functionality works perfectly fine at runtime. This is purely a static analysis issue.