Skip to content

Commit 95e51bb

Browse files
pbelevichfacebook-github-bot
authored andcommitted
change BuildExtension.with_options to return a class not a c-tor (pytorch#40121)
Summary: Pull Request resolved: pytorch#40121 Test Plan: Imported from OSS Reviewed By: ezyang Differential Revision: D22076634 Pulled By: pbelevich fbshipit-source-id: a89740baf75208065e418d7f972eeb52db9ee3cf
1 parent a71aefe commit 95e51bb

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

torch/utils/cpp_extension.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,15 @@ class BuildExtension(build_ext, object):
312312
@classmethod
313313
def with_options(cls, **options):
314314
r'''
315-
Returns an alternative constructor that extends any original keyword
315+
Returns a subclass with alternative constructor that extends any original keyword
316316
arguments to the original constructor with the given options.
317317
'''
318-
def init_with_options(*args, **kwargs):
319-
kwargs = kwargs.copy()
320-
kwargs.update(options)
321-
return cls(*args, **kwargs)
322-
return init_with_options
318+
class cls_with_options(cls):
319+
def __init__(self, *args, **kwargs):
320+
kwargs.update(options)
321+
super().__init__(*args, **kwargs)
322+
323+
return cls_with_options
323324

324325
def __init__(self, *args, **kwargs):
325326
super(BuildExtension, self).__init__(*args, **kwargs)

0 commit comments

Comments
 (0)