Skip to content

Conversation

@karimkhaleel
Copy link
Contributor

Mypy doesn't like __init__ in path names.

dmypy suggest a.__ini__.foo
Unknown class a.__ini__

Stripping them out of the modpath gets __init__.py files to be annotated like other files. Couldn't get it to work for __main__.py files though.

dmypy suggest a.foo
() -> None

relative.removesuffix('.py')
.replace('/', '.')
.replace('\\', '.')
.replace(".__init__", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be removesuffix -- can you add an additional test demonstrating this mistake as well? (a.__init__somethingelse.b for example)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're absolutely right. amended with a fix.

@karimkhaleel karimkhaleel force-pushed the Fix-annotating-__init__.py-files-by-stripping-__init__-from-modpath branch 2 times, most recently from 7bc6a48 to 1f690c0 Compare April 29, 2025 01:36
@karimkhaleel karimkhaleel force-pushed the Fix-annotating-__init__.py-files-by-stripping-__init__-from-modpath branch from 1f690c0 to 229bc90 Compare April 29, 2025 01:38
Copy link
Contributor

@asottile-sentry asottile-sentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asottile-sentry asottile-sentry merged commit 349d321 into getsentry:main Apr 29, 2025
11 checks passed
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