Skip to content

Distinguish str from Iterable[str] in arguments #64

Closed
@abelcheung

Description

@abelcheung

It is a common typing problem that str can actually be used in Iterable[str] arguments and most likely cause undesirable effect. We should find all places where such problem may occur (including Collection[str] and Sequence[str] as well as bytes counterparts), and use warnings.deprecated to intercept str usage. Potentially problematic functions / methods below:

  • etree._ElementTree.write(method='c14n',inclusive_ns_prefixes=...) (06f868b)
  • etree.C14NWriterTarget.__init__(...) (116376d)
  • etree.Extension(function_mapping=...) (ff2fde8)
  • etree.canonicalize(...) (116376d)
  • etree.cleanup_namespaces(keep_ns_prefixes=...)
  • etree.fromstringlist(strings=...) (bc8798b)
  • etree.strip_attributes(__attrib=...) (d0c43e8)
  • etree.tostring(method='c14n',inclusive_ns_prefixes=...) (06f868b)
  • html.soupparser.fromstring(exclude_encodings=...) (68facbc)
  • html.soupparser.parse(exclude_encodings=...) (68facbc)

Note that only pyright would provide deprecation warnings, and therefore only pylance users can see the UI cue that something in their code isn't right. It remains unsupported as of mypy 1.13, though there is apparently some progress in python/mypy#17476 and python/mypy#18192 though.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions