bpo-29901: Improve support of path-like objects in zipapp 分析

bpo-29901 簡介

新知

  • os.PathLike: https://docs.python.org/3/library/os.html#os.PathLike
  • path-like object: https://docs.python.org/3.7/glossary.html#term-path-like-object
  • Lib/zipapp (from version 3.5): https://docs.python.org/3/library/zipapp.html
  • Lib/pathlib (from version 3.4): https://docs.python.org/3/library/pathlib.html

技巧

isinstance 的 classinfo 可以傳入 tuple

from Python 3.6 docs:

isinstance(object, classinfo)
Return true if the object argument is an instance of the classinfo argument, or of a (direct, indirect or virtual) subclass thereof. If object is not an object of the given type, the function always returns false. If classinfo is a tuple of type objects (or recursively, other such tuples), return true if object is an instance of any of the types. If classinfo is not a type or tuple of types and such tuples, a TypeError exception is raised.

ZipFile itself converts the archive name to POSIX format. But I think it is better to do this explicity. Maybe implicit conversion will be deprecated in future.

 




如果你覺得這篇文章不錯,歡迎打賞 IOTA:RFHEIVXVIZWJFXTZORZZRCMHZF9PSGFUFWAAKXTFNZE9JQUY9HFQREJYYSPSXDRLECKXCAQQDOMSMYJYDKPCKWXBKD

或是點選下方圖片贊助我一杯咖啡:

Leave a reply:

Your email address will not be published.

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料