Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么 Python 不支持函数重载? #3

Open
chinesehuazhou opened this issue Dec 7, 2022 · 0 comments
Open

为什么 Python 不支持函数重载? #3

chinesehuazhou opened this issue Dec 7, 2022 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@chinesehuazhou
Copy link
Owner

函数重载指的是有多个同名的函数,但是它们的签名或实现有不同。

Python 中使用装饰器(例如 functools 库的 singledispatch),可以实现函数重载的效果。

然而,原生 Python 语法层面不支持函数重载。

初步原因:locals 命名空间中不允许出现同名函数

TODO:语言设计时的考虑?相关历史讨论线索?

@chinesehuazhou chinesehuazhou added help wanted Extra attention is needed good first issue Good for newcomers labels Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant