weixin_39633437
weixin_39633437
2020-11-29 16:06

Add stubs for bleach

Permission in mozilla/bleach#424

该提问来源于开源项目:python/typeshed

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • weixin_39633437 weixin_39633437 5月前

    I have updated the stubs now to support Python 2. But I wonder whether we should require contributors to provide Python 2 compatible stubs when they submit new stubs. (Of course existing stubs that support Python 2 should continue to do so.) Making stubs Python 2 compatible requires quite a bit of additional work and it's quite possible that a Python 2 version is not that useful anyway, considering Python 2's end of life date.

    Personally I suggest, we accept Python 3-only stubs (and also Python 2-only stubs), even if the library supports both versions. Support for the other Python version can always be added later by an interested party.

    点赞 评论 复制链接分享
  • weixin_39633437 weixin_39633437 5月前

    Gentle ping

    点赞 评论 复制链接分享
  • weixin_39579726 weixin_39579726 5月前

    Sorry for dropping this!

    点赞 评论 复制链接分享
  • weixin_39865625 weixin_39865625 5月前

    Just installed the new version of mypy and I'm getting some errors on my codebase now from these stubs. Specifically, I'm using bleach's Cleaner class, which has its __init__ stub as:

    python
    class Cleaner(object):
        def __init__(
            self,
            tags: List[Text] = ...,
            attributes: Any = ...,
            styles: List[Text] = ...,
            protocols: List[Text] = ...,
            strip: bool = ...,
            strip_comments: bool = ...,
            filters: Optional[List[Type[_Filter]]] = ...,
        ) -> None: ...
    

    I'm passing tuples for both tags= and protocols=, which works fine but doesn't satisfy these stubs. Maybe the stubs should use Sequence instead of explicitly defining List (both here and other places where that's relevant)?

    Also, I'm passing a list containing a partial object for filters=. Using a partial object this way is shown in the documentation as a way to both sanitize and linkify in the same step. However, the current stubs throw the following error for doing this:

    error: List item 0 has incompatible type "partial[LinkifyFilter]"; expected "Type[Any]"
    

    would you be able to fix these issues? I could probably also submit a pull request myself to adjust them, if you'd like (though I've never contributed any stubs before so I'm not very familiar with any of what goes into it).

    点赞 评论 复制链接分享
  • weixin_39633437 weixin_39633437 5月前

    We welcome pull requests and we can help if you are stuck.

    点赞 评论 复制链接分享

相关推荐