My app has been passing mypy static type checks just great until I upgraded from 1.22.1 to 1.22.2.
I've removed some of the errors below for brevity.
$ pip freeze | grep chalice
chalice==1.22.1
$ mypy --config-file mypy.ini chalicelib
✅ Success: no issues found in 82 source files
$ pip install chalice==1.22.2 --upgrade
$ mypy --config-file mypy.ini chalicelib
chalicelib/init_app.py:9: error: "APIGateway" has no attribute "cors"
chalicelib/routes/main.py:11: error: Module 'chalice.app' has no attribute 'MultiDict'
chalicelib/routes/main.py:13: error: Too many arguments for "Blueprint"
chalicelib/routes/main.py:41: error: Incompatible types in assignment (expression has type "Union[str, Dict[str, Any]]", variable has type "Dict[str, Any]")
chalicelib/routes/docs_route.py:28: error: Too many arguments for "Blueprint"
chalicelib/util/authorizer.py:80: error: Too many arguments for "AuthResponse"
chalicelib/routes/type_route.py:8: error: Module 'chalice.app' has no attribute 'MultiDict'
chalicelib/routes/type_route.py:14: error: Too many arguments for "Blueprint"
chalicelib/routes/transaction_route.py:63: error: Argument 2 to "Response" has incompatible type "None"; expected "Dict[str, str]"
chalicelib/routes/transaction_route.py:66: error: Too many arguments for "Blueprint"
chalicelib/routes/search_route.py:4: error: Module 'chalice.app' has no attribute 'MultiDict'
chalicelib/routes/search_route.py:10: error: Too many arguments for "Blueprint"
<snip/>
🚫 Found 38 errors in 24 files (checked 82 source files)
I can't see why. What has changed in chalice, and why is my code failing mypy now?
Example of failed static typechecking from init_app.py:
chalicelib/init_app.py:9: error: "APIGateway" has no attribute "cors"
from chalice import Chalice, CORSConfig
APP = Chalice(app_name='myapp')
APP.api.cors = CORSConfig(
allow_origin = '*',
allow_credentials=True
)
My team also faced this problem in the services we are working on.
Example:
tests/mocks/mock_sqs.py:8: error: Module 'chalice.app' has no attribute 'SQSRecord'
chalicelib/receiver.py:7: error: Module 'chalice.app' has no attribute 'SQSRecord'
app.py:6: error: Module 'chalice.app' has no attribute 'CloudWatchEvent'; maybe "CloudWatchEventConfig"?
app.py:6: error: Module 'chalice.app' has no attribute 'SQSEvent'
app.py:95: error: Too many arguments for "Cron"
Found 5 errors in 3 files (checked 31 source files)
I'm guessing this is from https://github.com/aws/chalice/pull/1652 which updated the app.pyi stub file and also added it to the whl/sdist.
@jamesls yes it was adding it to the release that broke things.
It would be good if there was a stricter application of semantic versioning so things like this aren’t slipped into patch level releases. We had to patch 60+ services due to this bug. Once that was done we had to rerun hundreds of builds. It was pretty frustrating.
Really sorry to hear that. I think the assumption was that the app.pyi was accurate so including it as part of the dist package wouldn't be impactful. I'll look into how we can something into our CI process to catch invalid app.pyi.
https://github.com/aws/chalice/pull/1677 has been merged, I'm doing another pass to verify there's no other issues with the stub file.
@jamesls thanks for merging the pull request. When do you think you can cut 1.22.3?
Most helpful comment
My team also faced this problem in the services we are working on.
Example:
tests/mocks/mock_sqs.py:8: error: Module 'chalice.app' has no attribute 'SQSRecord' chalicelib/receiver.py:7: error: Module 'chalice.app' has no attribute 'SQSRecord' app.py:6: error: Module 'chalice.app' has no attribute 'CloudWatchEvent'; maybe "CloudWatchEventConfig"? app.py:6: error: Module 'chalice.app' has no attribute 'SQSEvent' app.py:95: error: Too many arguments for "Cron" Found 5 errors in 3 files (checked 31 source files)