-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
Should PackageMetadata.get be supported? #384
Comments
The specific use case I have for using |
tl;dr - yes, it's an implementation detail. This is another case (similar to #371), where the duck-typing approach has left ambiguity. This project has provided a viable implementation but not a rigorously specified one. In more recent releases, That said, perhaps PackageMetadata should supply What about using the Or alternately, does |
importlib.metadata.metadata(name).get(key)
is used in the wild -- is its existence intentional, or an implementation detail?
@jaraco thank you for the clarification, I appreciate it! My usecase was resolved by switching from |
Supporting try:
description: Optional[str] = metadata("bork")["Description"]
except KeyError:
description = None That's just a little bit irritating. I suppose: description = metadata("bork").json.get("Description") isn't too bad, although sort of weird (and not really documented as the way to get that behavior). My primary motivation in asking was that it seemed likely that most implementations either already support |
…in `phylum-init` * Check for valid versions by using the GitHub API to compare against actual releases * Supported target triples programmatically generated based on the results * Users will be told when the version provided as an option is not valid * Removed `SUPPORTED_TARGET_TRIPLES` static collection * Add `--list-releases` and `--list-targets` options * These are mutually exclusive options * Listing Rust target triples are for a specific release version * Format and refactor throughout * Stop using `.get` method on `importlib_metadata.metadata()` results * See python/importlib_metadata#384 * Add constant for `MIN_SUPPORTED_CLI_VERSION`
…in `phylum-init` (#74) * Check for valid versions by using the GitHub API to compare against actual releases * Supported target triples programmatically generated based on the results * Users will be told when the version provided as an option is not valid * Removed `SUPPORTED_TARGET_TRIPLES` static collection * Add `--list-releases` and `--list-targets` options * These are mutually exclusive options * Listing Rust target triples are for a specific release version * Format and refactor throughout * Stop using `.get` method on `importlib_metadata.metadata()` results * See python/importlib_metadata#384 * Add constant for `MIN_SUPPORTED_CLI_VERSION`
Let me illustrate what I was suggesting here with an example: description = dict(metadata("bork")).get("Description") Granted, that approach is a bit convoluted and not performant (creates an entire copy of the metadata to extract one value). There seems to be a reasonable expectation that |
add .get() to the PackageMetadata protocol Fixes #384.
This isn't a feature request. I'm looking for a quick clarification, so other folks who encounter python/typeshed#7767 have a definitive answer.
In the wild, I've seen things like this:
Both the stdlib documentation and the readthedocs documentation never mention
.get()
, andPackageMetadata
does not define it. Due to that, using it and running mypy returnserror: "PackageMetadata" has no attribute "get"
. I suspect I made a bad assumption when I used it, but if so it's one I've seen other folks make — so it seems worthwhile to get an explicit answer on whether leaving it out is deliberate.So, my question is this:
Is
.get()
an implementation detail that folks latched on to and should migrate away from? Or should it be added toPackageMetadata
?The text was updated successfully, but these errors were encountered: