Conversation
import_names and import_namespaces (both Metadata 2.5 / PEP 794) share a processor and are validated the same way, but only import_names special-cases the empty-list value. As a result import_namespaces=[] is dropped on as_rfc822() and parses back as None, and a bare Import-Namespace: header raises on parse instead of yielding []. Both special cases were added for import_names in e83801f (pypa#948) and weren't mirrored to import_namespaces. Extend the parse ([""] -> []) and write ([] -> "") branches to cover import_namespaces, and add a round-trip regression test parametrized over both fields.
Contributor
|
In PEP 794, Import-Name and Import-Namespaces are not symmetric.
Only Import-Name is allowed to be empty. This is to allow no import at all to be represented, but it must be represented as an empty Import-Name. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
import_namesandimport_namespaces(both added in Metadata 2.5 / PEP 794) share a processor and are validated the same way, but onlyimport_namesspecial-cases the empty-list value.import_namespacesdoes not, so on 26.3:Metadata.from_raw({..., "import_namespaces": []})is accepted, butas_rfc822()drops the field entirely, and parsing the output back givesNoneinstead of[].Import-Namespace:header raisesinvalid or unparsed metadataon parse: the value[""]reaches_process_import_names, where"".isidentifier()is false. A bareImport-Name:parses to[].Both special cases (
[""]->[]on parse,[]->""on write) were added forimport_namesin e83801f (#948), the commit that introduced both fields, and weren't mirrored toimport_namespaces. This extends both branches to cover it and adds a round-trip test parametrized over the two fields.Reproduced on 26.3: