bpo-28556: Minor fixes for typing module#6732
Conversation
|
Note this will not backport to 3.6 cleanly. I will make a manual backport. |
|
I approved, but tests are failing...
|
|
It looks like all failures are unrelated except for a useful warning about bad |
|
Hm, all tests passed now. So either they were flakes, or just they got fixed in the meantime. I think it is safe to merge now. |
|
Thanks @ilevkivskyi for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
This also fixes https://bugs.python.org/issue33420 (cherry picked from commit 43d12a6) Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
|
GH-6735 is a backport of this pull request to the 3.7 branch. |
This also fixes https://bugs.python.org/issue33420 (cherry picked from commit 43d12a6) Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
| "follow default field(s) {default_names}" | ||
| .format(field_name=field_name, | ||
| default_names=', '.join(defaults_dict.keys()))) | ||
| nm_tpl.__new__.__annotations__ = collections.OrderedDict(types) |
There was a problem hiding this comment.
Why OrderedDict? dict is ordered.
There was a problem hiding this comment.
To make code closer to the backported version (plus there is another occurrence above). At some point however we might want to clean-up all this, but I propose to make it a separate PR.
| raise TypeError("Type Generic cannot be instantiated; " | ||
| "it can be used only as a base class") | ||
| return super().__new__(cls) | ||
| if super().__new__ is object.__new__: |
There was a problem hiding this comment.
I think and cls.__init__ is not object.__init__ is needed here.
The test:
class A(Generic[T]):
pass
with self.assertRaises(TypeError):
A('foo')And would extract the subexpression super().__new__ into a variable.
There was a problem hiding this comment.
Hm, indeed, in the original PR in typing repo we were concerned that it may fail when it shouldn't, but forgot that it also should fail when it should. @gvanrossum what do you think?
There was a problem hiding this comment.
Yes, @serhiy-storchaka is right. This is definitely a wart -- object.__init__ and object.__new__ each ignore extra arguments only when the other is overridden (and they themselves are not).
This also fixes https://bugs.python.org/issue33420
https://bugs.python.org/issue28556