-
Notifications
You must be signed in to change notification settings - Fork 273
Description
Originally reported by: Evan (Bitbucket: evan_, GitHub: Unknown)
The current signature of with_metaclass is awkward in that it puts the metaclass before the bases, whereas declaring classes naturally in Python 3 puts the metaclass last as a keyword-only argument, e.g. class Class(base1, base2, metaclass=meta). Keyword-only arguments aren't supported by Python 2, but they can be faked by accepting **kwargs and doing a bit of filtering.
There are two ways of implementing this without breaking backwards compatibility:
-
Update
with_metaclassto handle both ways of passing arguments, falling back to the original signature ifmetaclassis not given as a keyword argument. This is the simplest, but people unfamiliar with keyword-only arguments may assume from the signaturewith_metaclass(*bases, metaclass)that they are able to dowith_metaclass(base1, base2, meta), which will end up usingbase1as the metaclass with no warning. -
Create another function which is a simple wrapper around
with_metaclass. This function could mimic a real keyword-only argument, in which caseother_function(base1, base2, meta)would raise aTypeError. This could optionally also involve deprecatingwith_metaclass.
Thoughts? Happy to do a PR to implement this.
- Bitbucket: https://bitbucket.org/gutworth/six/issue/162