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

Upgrading 4.3.2 -> 4.4.1 causes mypy type checking to fail #2186

Open
rakunoi opened this issue Oct 3, 2023 · 4 comments
Open

Upgrading 4.3.2 -> 4.4.1 causes mypy type checking to fail #2186

rakunoi opened this issue Oct 3, 2023 · 4 comments

Comments

@rakunoi
Copy link

rakunoi commented Oct 3, 2023

Hi,

to keep it short, when upgraded 4.3.2 -> 4.4.1, mypy started throwing following errors

Skipping analyzing "troposphere": module is installed, but missing library stubs
or py.typed marker  [import]
    from troposphere import Ref
    ^
Skipping analyzing "troposphere.ecs": module is installed, but missing library
stubs or py.typed marker  [import]
    from troposphere.ecs import Environment as EnvironmentVariable
    ^
Skipping analyzing "troposphere": module is installed, but missing library stubs
or py.typed marker  [import]
    from troposphere import (
    ^
Skipping analyzing "troposphere.applicationautoscaling": module is installed,
but missing library stubs or py.typed marker  [import]
    from troposphere.applicationautoscaling import (
    ^

Skipping analyzing "troposphere.cloudwatch": module is installed, but missing
library stubs or py.typed marker  [import]
    from troposphere.cloudwatch import Alarm, MetricDimension
    ^

Skipping analyzing "troposphere.ec2": module is installed, but missing library
stubs or py.typed marker  [import]
    from troposphere.ec2 import SecurityGroup, SecurityGroupEgress, Securi...
    ^

Skipping analyzing "troposphere.ecs": module is installed, but missing library
stubs or py.typed marker  [import]
    from troposphere.ecs import (
    ^

Skipping analyzing "troposphere.efs": module is installed, but missing library
stubs or py.typed marker  [import]
    from troposphere.efs import (
    ^

Skipping analyzing "troposphere.elasticloadbalancingv2": module is installed,
but missing library stubs or py.typed marker  [import]
    from troposphere.elasticloadbalancingv2 import (
    ^

mypy config is

[tool.mypy]
python_version = "3.11"
strict = true
pretty = true
show_error_codes = true
warn_unused_ignores = false
plugins = ["pydantic.mypy"]

Pydantic version is "==1.10.12"
Mypy version is mypy = "1.5.1"

Please let me know if more information is needed.

@markpeek
Copy link
Member

markpeek commented Oct 3, 2023

There was an issue with py.typed being included in Release 4.3.2 which was fixed. This is related to this earlier issue describing why it should not be included at this time. At this time exclude troposphere from the mypy checks.

@g-borgulya
Copy link

It's probably a mypy related question, but rather bring it up here, as this whole mypy "which modules to ignore and how" is pretty confusing (seemingly to many).

I've tried to add both below to the mypy.ini, but neither of them helped:

[mypy-troposhpere.*]
ignore_missing_imports = True

[mypy-troposhpere]
ignore_missing_imports = True

Still getting error: Skipping analyzing "troposphere": module is installed, but missing library stubs or py.typed marker [import-untyped] when running mypy on the selected files.

Putting it to the top level makes running mypy ignore the issue, but that's not ideal as it affects other packages as well:

[mypy]
ignore_missing_imports = True

This results in Success: no issues found in 82 source files.

(It's another issue though that with this setting I'm still getting Stub file not found for "troposphere" from PyLance in VSCode.)

I'd really appreciate any recommendations how to get this working properly, I've spent at least an hour with this specifically because of troposphere.

@markpeek
Copy link
Member

@g-borgulya I was able to reproduce with your example. I believe the issue was the spelling of "troposphere" in the section names. Here's my results correcting that issue.

$ cat m.py
import troposphere

print(troposphere.__version__)
t = troposphere.Template()
print(t.to_json())
$ python m.py
4.5.3
{
 "Resources": {}
}
$ cat mypy.ini
[mypy]

[mypy-troposphere.*]
ignore_missing_imports = True

[mypy-troposphere]
ignore_missing_imports = True
$ mypy m.py
Success: no issues found in 1 source file
$

Let me know if this works for you. I do need to create a tracking issue and branch to get better typing support implemented.

@g-borgulya
Copy link

I so much appreciate it, @markpeek ! Thank you. Yes, mypy works with the fixed settings.

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

No branches or pull requests

3 participants