-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
bpo-33190: elucidated types.new_class docstring
#6317
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,27 @@ def _m(self): pass | |
|
|
||
| # Provide a PEP 3115 compliant mechanism for class creation | ||
| def new_class(name, bases=(), kwds=None, exec_body=None): | ||
| """Create a class object dynamically using the appropriate metaclass.""" | ||
| """Create a class object dynamically using the appropriate metaclass. | ||
|
|
||
| Arguments: | ||
| name -- the new class name | ||
| bases -- sequence of parent classes (default ()) | ||
| kwds -- mapping of keyword arguments to be supplied to parents' `__init_subclass__` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not only passed to |
||
| exec_body -- a callback used to populate the freshly created class namespace | ||
|
|
||
| Note: the class-creation functionality of `new_class` is similar to `type`. However, | ||
| calls to `type` cannot be directly substituted by calls to `new_class`. For example: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although, you were hit but this particular problem, I don't think it deserves a dedicated note. Just describing clearly every argument is enough. Plus maybe an example of usage like this: |
||
|
|
||
| type("MyClass", (), dict(my_method=lambda self: None)) | ||
|
|
||
| ...is not equivalent to the below, which will produce a `TypeError`: | ||
|
|
||
| new_class("MyClass", (), dict(my_method=lambda self: None)) | ||
|
|
||
| Instead, the correct way to use `new_class` in this instance is: | ||
|
|
||
| new_class("MyClass", (), {}, lambda ns: ns.update(dict(my_method=lambda self: None))) | ||
| """ | ||
| resolved_bases = resolve_bases(bases) | ||
| meta, ns, kwds = prepare_class(name, resolved_bases, kwds) | ||
| if exec_body is not None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please indent the argument list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to do it just like in PEP 257 which doesn't have indentation. But I'll indent next time.