-
Notifications
You must be signed in to change notification settings - Fork 251
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
Migrate anonymous Mapping[str, Any] to TypedDicts where their content is fully defined. #716
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
I do not know why the integration tests are failing, I've added typing_extensions as a dependency to the main pyproject.toml however the integration tests still indicate the following:
I am not entirely sure what this is, I'll look further into how your tests are constructed tomorrow but if anyone else wants to sort this out that'd be great :) |
In general, our stance is that @dimbleby Since you are familiar with vendoring and contributing many typing improvements, I'd appreciate your opinion. |
In python-poetry/poetry#9251 we have established that so long as all imports of typing-extensions can be moved behind Over in poetry I have objected to this approach: it feels fragile and non-obvious and who cares about another dependency anyway? Over here it still feels fragile and non-obvious - but the case for wanting to avoid the dependency is stronger. So that is an option. |
Ah I see, thanks for the info @dimbleby. I also don't like this approach, but I do see the reasoning behind it. Another side-effect of this that I don't like is that I've had to add poetry-core/src/poetry/core/factory.py Lines 215 to 225 in c47aad1
I don't like this at all, like you said it seems non-obvious and very fragile. Any ideas for how to make mypy happy without having this ugliness in the code? |
Quality Gate passedIssues Measures |
Iirc you can cast to the string |
build = config["build"] | ||
if not build: | ||
build = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build = config["build"] | |
if not build: | |
build = {} | |
build = config.get("build", {}) |
?
@@ -66,7 +66,7 @@ def _module(self) -> Module: | |||
formats = [formats] | |||
|
|||
if ( | |||
formats | |||
len(formats) > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that make a difference? Isn't the former more Pythonic?
BuildConfigSpec = TypedDict( | ||
"BuildConfigSpec", | ||
{"script": NotRequired[str], "generate-setup-file": NotRequired[bool]}, | ||
) | ||
|
||
class PackageSpec(TypedDict): | ||
include: str | ||
to: str | ||
format: list[SupportedPackageFormats] | ||
|
||
class IncludeSpec(TypedDict): | ||
path: str | ||
format: list[SupportedPackageFormats] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these were Mappings
before and thus immutable for a reason (see comment in ProjectPackage.__init__
), we probably should declare all attributes as ReadOnly.
class PackageSpec(TypedDict): | ||
include: str | ||
to: str | ||
format: list[SupportedPackageFormats] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be a Sequence
.
|
||
class IncludeSpec(TypedDict): | ||
path: str | ||
format: list[SupportedPackageFormats] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be a Sequence
.
When developing a plugin for Poetry, I found that despite the "include", "exclude" and "package" mapping content being fully defined in the documentation, no type hints were available to help me. Therefore I propose this minor change. It has no impact on current functionality, however with this IDEs like PyCharm and VSCode are aware of the structure of these dicts.
Other similar changes may be useful elsewhere in the code. I'll continue to explore the codebase and see what I can do.