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

Fix suggested changes from #820 #821

Merged
merged 1 commit into from
Jan 16, 2022

Conversation

flaeppe
Copy link
Member

@flaeppe flaeppe commented Jan 16, 2022

Fixes some additional suggested changes in #820. Just minor cleanup really.

Related issues

Refs #820

@flaeppe flaeppe force-pushed the fix/820-additional-changes branch from 1f0975c to 572c64b Compare January 16, 2022 12:48
@flaeppe flaeppe force-pushed the fix/820-additional-changes branch from 572c64b to a7cc58d Compare January 16, 2022 13:04
new_manager_info.metadata.setdefault("django", {})
new_manager_info.metadata["django"].setdefault("from_queryset_manager", {})
new_manager_info.metadata["django"]["from_queryset_manager"] = derived_queryset_fullname
new_manager_info.metadata["django"] = {"from_queryset_manager": derived_queryset_fullname}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing this slightly decreases compatibility if some other tool were to use the "django" namespace in the metadata dict?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it does. Though the top-level metadata key is set as "django" throughout django-stubs.

Copy link
Member Author

@flaeppe flaeppe Jan 16, 2022

Choose a reason for hiding this comment

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

With a quick peek I saw that it's not always the case that "django" is included. Mypy mentions that it's intended for a plugin to have a top-level metadata key coinciding with the plugin name:

https://github.com/python/mypy/blob/254d41e10a353612d5edfdcb8b23b8e90508830b/mypy/plugin.py#L43-L48

Although, I suppose that the key should perhaps be "django-stubs" instead

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I'm probably bike-shedding. Seems highly unlikely that there will be conflicts. And if there are, it can be addressed in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, although to perhaps minimize custom metadata usage. It could be useful with some helper to set metadata values(?). Basically just to keep the same top-level name.

def set_metadata_value(key: str, value: Any, info: TypeInfo) -> None:
    info.metadata.setdefault("django-stubs", {})
    info.metadata["django-stubs"][key] = value

Copy link
Member Author

Choose a reason for hiding this comment

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

For reference, SQLAlchemy's mypy plugin has a utility getter/setter for TypeInfo metadata: https://github.com/sqlalchemy/sqlalchemy/blob/eb716884a4abcabae84a6aaba105568e925b7d27/lib/sqlalchemy/ext/mypy/util.py#L90-L95

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thank you!

@sobolevn sobolevn merged commit a9e41a8 into typeddjango:master Jan 16, 2022
@flaeppe flaeppe deleted the fix/820-additional-changes branch January 16, 2022 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants