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

mypy errors starting with release 3.2.0 #2003

Merged
merged 1 commit into from
Jan 12, 2022
Merged

mypy errors starting with release 3.2.0 #2003

merged 1 commit into from
Jan 12, 2022

Conversation

danielnovotny-wf
Copy link
Contributor

Summary

Starting with release version 3.2.0 we began getting mypy errors that did not used to exist when using version 3.1.1.

Details

As part of the commit that introduced the new PropsDictType variable, the troposphere/py.typed file was also added. In accordance with PEP 561, the presence of this file should be used when the underlying code has types or stubs defined. The example below demonstrates how the py.typed can cause mypy to throw errors that did not trigger before.

example.py

from troposphere import Template
import troposphere.ec2 as ec2
t = Template()
instance = ec2.Instance("myinstance")
instance.ImageId = "ami-951945d0"
instance.InstanceType = "t1.micro"
t.add_resource(instance)
print(t.to_yaml())

setup.cfg

[mypy]
disallow_any_generics = True
disallow_incomplete_defs = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_decorators = True
disallow_untyped_defs = True
exclude = scripts
ignore_missing_imports = True
no_implicit_optional = True
show_error_codes = True

mypy errors

$ python3 --version
Python 3.7.10

$ pip3 install mypy

$ pip3 install troposphere==3.1.1
$ mypy example.py 
Success: no issues found in 1 source file

$ pip3 install troposphere==3.2.2
$ mypy example.py 
example.py:3: error: Call to untyped function "Template" in typed context  [no-untyped-call]
example.py:4: error: Call to untyped function "Instance" in typed context  [no-untyped-call]
example.py:7: error: Call to untyped function "add_resource" in typed context  [no-untyped-call]
example.py:8: error: Call to untyped function "to_yaml" in typed context  [no-untyped-call]
Found 4 errors in 1 file (checked 1 source file)

$ rm lib/python3.7/site-packages/troposphere/py.typed 
$ mypy example.py 
Success: no issues found in 1 source file

Suggested Solution

Until troposphere fully supports typing across its codebase, I would suggest we remove the py.typed file.

@markpeek markpeek merged commit cc640a2 into cloudtools:main Jan 12, 2022
@markpeek
Copy link
Member

Thank you for the change and detailed report on why py.typed should be removed for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants