title: Weekly 2020-11-0x01description: [hackettyu’weekly]
keywords: Python Vscode Wikipedia APSD
Note
Python
NewType
利用 NewType 可以定义一个新的检查类型
from typing import NewTypeUserId = NewType('UserId', int)some_id = UserId(524313)
Callable type
Callable[[int], str] is a function of (int) -> str.
Optional type
You can use Optional[X] as a shorthand for Union[X, None].
Literal type
A type that can be used to indicate to type checkers that the corresponding variable or function parameter has a value equivalent to the provided literal (or one of several literals). For example:
def validate_simple(data: Any) -> Literal[True]: # always returns True
...
MODE = Literal['r', 'rb', 'w', 'wb']
def open_helper(file: str, mode: MODE) -> str:
...
open_helper('/some/path', 'r') # Passes type check
open_helper('/other/path', 'typo') # Error in type checker
Final type
A special typing construct to indicate to type checkers that a name cannot be re-assigned or overridden in a subclass. For example:
MAX_SIZE: Final = 9000
MAX_SIZE += 1 # Error reported by type checker
class Connection:
TIMEOUT: Final[int] = 10
class FastConnector(Connection):
TIMEOUT = 1 # Error reported by type checker
Constant type
TYPE_CHECKING type
A special constant that is assumed to be True by 3rd party static type checkers. It is False at runtime. Usage:
if TYPE_CHECKING:
import expensive_mod
def fun(arg: 'expensive_mod.SomeType') -> None:
local_var: expensive_mod.AnotherType = other_fun()
The first type annotation must be enclosed in quotes, making it a “forward reference”, to hide the expensive_mod reference from the interpreter runtime. Type annotations for local variables are not evaluated, so the second annotation does not need to be enclosed in quotes.
软件设计哲学笔记
https://github.com/gdut-yy/A-Philosophy-of-Software-Design-zh/blob/master/docs/ch7.md
创建装饰器类之前,请考虑以下替代方法:
您能否将新功能直接添加到基础类,而不是创建装饰器类?如果新功能是相对通用的,或者在逻辑上与基础类相关,或者如果基础类的大多数使用也将使用新功能,则这是有意义的。例如,几乎每个创建 Java InputStream 的人都会创建一个 BufferedInputStream,并且缓冲是 I/O 的自然组成部分,因此应该合并这些类。
如果新功能专用于特定用例,将其与用例合并而不是创建单独的类是否有意义?
您可以将新功能与现有的装饰器合并,而不是创建新的装饰器吗?这将导致一个更深的装饰器类,而不是多个浅的装饰器类。
最后,问问自己新功能是否真的需要包装现有功能
https://github.com/gdut-yy/A-Philosophy-of-Software-Design-zh/blob/master/docs/ch11.md
“两次设计”方法不仅可以改善您的设计,而且可以提高您的设计技能。设计和比较多种方法的过程将教您使设计更好或更坏的因素。随着时间的流逝,这将使您更容易排除不良的设计并磨练真正的出色设计
https://github.com/gdut-yy/A-Philosophy-of-Software-Design-zh/blob/master/docs/ch13.md
我最近一直在尝试一种方法,该方法将跨模块问题记录在一个名为 designNotes 的中央文件中。该文件分为清楚标记的部分,每个主要主题一个
Python doc
https://docs.python.org/zh-cn/3.8/glossary.html#term-docstring
Share
wikipedia 缩进风格
播客 shownotes 搜索引擎
wikipedia 计算机编程
中文自然语言 stopword
https://www.ranks.nl/stopwords/chinese-stopwords
v20201102: 的一不在人有是为以于上他而后之来及了因下可到由这与也此但并个其已无小我们起最再今去好只又或很亦某把那你乃它吧被比别趁当从到得打凡儿尔该各给跟和何还即几既看据距靠啦了另么每们嘛拿哪那您凭且却让仍啥如若使谁虽随同所她哇嗡往哪些向沿哟用于咱则怎曾至致着诸自
Vscode Extension: Increment Selection
https://marketplace.visualstudio.com/items?itemName=albymor.increment-selection
让 Vscode 支持序号查询的插件
Default Keymap
Win\Linux:
- ctrl + alt + I
- ctrl + shift + P => Increment Selection
Mac:
Release、Code(ZIP) 文件加速:
- https://gh.con.sh | 美国
- https://download.fastgit.org | 日本东京
- https://pd.zwc365.com | 中国香港 (相对下面的宽带更大一点
- https://g.ioiox.com | 中国香港 (10M 宽带但稳定,不会动不动下载中断,算是备用
- https://git.yumenaka.net | 美国洛杉矶(晚上时比前面两个美国的更快
Git Clone 加速:
- https://hub.fastgit.org | 中国香港
- https://gitclone.com | 中国浙江杭州
Raw 文件加速:
- https://cdn.jsdelivr.net | 中国国内
- https://raw.fastgit.org | 中国香港
- https://git.yumenaka.net | 美国洛杉矶
Tutorials
如何维护更新日志
变动类型:
- Added 新添加的功能。
- Changed 对现有功能的变更。
- Deprecated 已经不建议使用,准备很快移除的功能。
- Removed 已经移除的功能。
- Fixed 对bug的修复
- Security 对安全的改进
Python request advance usage
https://findwork.dev/blog/advanced-usage-python-requests-timeouts-retries-hooks/
