Skip to content

Commit 100a408

Browse files
committed
Fix whitespace in clrtype.py
1 parent 2c684b3 commit 100a408

1 file changed

Lines changed: 55 additions & 56 deletions

File tree

Src/IronPython/Lib/clrtype.py

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def validate_clr_types(signature_types, var_signature = False):
3434
if type(t) is type(System.IComparable): # type overloaded on generic arity, eg IComparable and IComparable[T]
3535
t = t[()] # select non-generic version
3636
clr_type = clr.GetClrType(t)
37-
if t == Void:
37+
if t == Void:
3838
raise TypeError("Void cannot be used in signature")
3939
is_typed = clr.GetPythonType(clr_type) == t
4040
# is_typed needs to be weakened until the generated type
@@ -53,7 +53,7 @@ class TypedFunction(object):
5353
"""
5454
A strongly-typed function can get wrapped up as a staticmethod, a property, etc.
5555
This class represents the raw function, but with the type information
56-
it is decorated with.
56+
it is decorated with.
5757
Other information is stored as attributes on the function. See propagate_attributes
5858
"""
5959
def __init__(self, function, is_static = False, prop_name_if_prop_get = None, prop_name_if_prop_set = None):
@@ -90,7 +90,7 @@ def emit_properties(self, typebld):
9090
for prop, prop_name, clr_prop_type in self.get_typed_properties():
9191
self.emit_property(typebld, prop, prop_name, clr_prop_type)
9292

93-
def emit_property(self, typebld, prop, name, clrtype):
93+
def emit_property(self, typebld, prop, name, clrtype):
9494
prpbld = typebld.DefineProperty(name, PropertyAttributes_None, clrtype, None)
9595
if prop.fget:
9696
getter = self.emitted_methods[(prop.fget.__name__, prop.fget.arg_types)]
@@ -100,13 +100,13 @@ def emit_property(self, typebld, prop, name, clrtype):
100100
prpbld.SetSetMethod(setter)
101101

102102
def dummy_function(self): raise RuntimeError("this should not get called")
103-
103+
104104
def get_typed_methods(self):
105105
"""
106106
Get all the methods with @accepts (and @returns) decorators
107107
Functions are assumed to be instance methods, unless decorated with @staticmethod
108108
"""
109-
109+
110110
# We avoid using the "types" library as it is not a builtin
111111
FunctionType = type(ClrType.__dict__["dummy_function"])
112112

@@ -134,9 +134,9 @@ def get_typed_methods(self):
134134

135135
def emit_methods(self, typebld):
136136
# We need to track the generated methods so that we can emit properties
137-
# referring these methods.
138-
# Also, the hash is indexed by name *and signature*. Even though Python does
139-
# not have method overloading, property getter and setter functions can have
137+
# referring these methods.
138+
# Also, the hash is indexed by name *and signature*. Even though Python does
139+
# not have method overloading, property getter and setter functions can have
140140
# the same __name__ attribute
141141
self.emitted_methods = {}
142142
for function_info in self.get_typed_methods():
@@ -166,19 +166,19 @@ def get_clr_type_name(self):
166166
return self.__name__
167167

168168
def create_type(self, typebld):
169-
self.emit_members(typebld)
170-
new_type = typebld.CreateType()
171-
self.map_members(new_type)
169+
self.emit_members(typebld)
170+
new_type = typebld.CreateType()
171+
self.map_members(new_type)
172172
return new_type
173173

174174
class ClrInterface(ClrType):
175175
"""
176176
Set __metaclass__ in a Python class declaration to declare a
177-
CLR interface type.
177+
CLR interface type.
178178
You need to specify object as the base-type if you do not specify any other
179179
interfaces as the base interfaces
180180
"""
181-
181+
182182
def __init__(self, *args):
183183
return super(ClrInterface, self).__init__(*args)
184184

@@ -191,7 +191,7 @@ def emit_method(self, typebld, function_info):
191191
attributes,
192192
function.return_type,
193193
function.arg_types)
194-
194+
195195
instance_offset = 0 if function_info.is_static else 1
196196
arg_names = function.__code__.co_varnames
197197
for i in range(len(function.arg_types)):
@@ -201,16 +201,16 @@ def emit_method(self, typebld, function_info):
201201
if hasattr(function, "CustomAttributeBuilders"):
202202
for cab in function.CustomAttributeBuilders:
203203
method_builder.SetCustomAttribute(cab)
204-
204+
205205
return method_builder
206-
206+
207207
def emit_members(self, typebld):
208208
self.emit_methods(typebld)
209209
self.emit_properties(typebld)
210210
self.emit_classattribs(typebld)
211211

212212
def map_members(self, new_type): pass
213-
213+
214214
interface_module_builder = None
215215

216216
@staticmethod
@@ -228,7 +228,7 @@ def define_interface(typename, bases):
228228
def map_clr_type(self, clr_type):
229229
"""
230230
TODO - Currently "t = clr.GetPythonType(clr.GetClrType(C)); t == C" will be False
231-
for C where C.__metaclass__ is ClrInterface, even though both t and C
231+
for C where C.__metaclass__ is ClrInterface, even though both t and C
232232
represent the same CLR type. This can be fixed by publishing a mapping
233233
between t and C in the IronPython runtime.
234234
"""
@@ -269,10 +269,10 @@ class ClrClass(ClrInterface):
269269
"""
270270
Set __metaclass__ in a Python class declaration to specify strong-type
271271
information for the class or its attributes. The Python class
272-
retains its Python attributes, like being able to add or remove methods.
272+
retains its Python attributes, like being able to add or remove methods.
273273
"""
274274

275-
# Holds the FieldInfo for a static CLR field which points to a
275+
# Holds the FieldInfo for a static CLR field which points to a
276276
# Microsoft.Scripting.Runtime.DynamicOperations corresponding to the current ScriptEngine
277277
dynamic_operations_field = None
278278

@@ -282,27 +282,27 @@ def emit_fields(self, typebld):
282282
field_type = self._clrfields[fldname]
283283
validate_clr_types(field_type)
284284
typebld.DefineField(
285-
fldname,
286-
clr.GetClrType(field_type),
285+
fldname,
286+
clr.GetClrType(field_type),
287287
FieldAttributes.Public)
288288

289289
def map_fields(self, new_type):
290290
if hasattr(self, "_clrfields"):
291-
for fldname in self._clrfields:
291+
for fldname in self._clrfields:
292292
fldinfo = new_type.GetField(fldname)
293293
setattr(self, fldname, ReflectedField(fldinfo))
294-
294+
295295
@staticmethod
296296
def get_dynamic_operations_field():
297-
if ClrClass.dynamic_operations_field:
297+
if ClrClass.dynamic_operations_field:
298298
return ClrClass.dynamic_operations_field
299299
python_context = clr.GetCurrentRuntime().GetLanguage(PythonContext)
300300
dynamic_operations = DynamicOperations(python_context)
301-
301+
302302
typegen = Snippets.Shared.DefineType(
303-
"DynamicOperationsHolder" + str(hash(python_context)),
304-
object,
305-
True,
303+
"DynamicOperationsHolder" + str(hash(python_context)),
304+
object,
305+
True,
306306
False)
307307
typebld = typegen.TypeBuilder
308308
typebld.DefineField(
@@ -311,22 +311,22 @@ def get_dynamic_operations_field():
311311
FieldAttributes.Public | FieldAttributes.Static)
312312
new_type = typebld.CreateType()
313313
ClrClass.dynamic_operations_field = new_type.GetField("DynamicOperations")
314-
314+
315315
ClrClass.dynamic_operations_field.SetValue(None, dynamic_operations)
316-
316+
317317
return ClrClass.dynamic_operations_field
318-
318+
319319
def emit_typed_stub_to_python_method(self, typebld, function_info):
320320
function = function_info.function
321321
"""
322-
Generate a stub method that repushes all the arguments and
322+
Generate a stub method that repushes all the arguments and
323323
dispatches to DynamicOperations.InvokeMember
324324
"""
325325
invoke_member = clr.GetClrType(DynamicOperations).GetMethod(
326-
"InvokeMember",
326+
"InvokeMember",
327327
Array[Type]((object, str, Array[object])))
328328

329-
# Type.GetMethod raises an AmbiguousMatchException if there is a generic and a non-generic method
329+
# Type.GetMethod raises an AmbiguousMatchException if there is a generic and a non-generic method
330330
# (like DynamicOperations.GetMember) with the same name and signature. So we have to do things
331331
# the hard way
332332
get_member_search = [m for m in clr.GetClrType(DynamicOperations).GetMethods() if m.Name == "GetMember" and not m.IsGenericMethod and m.GetParameters().Length == 2]
@@ -365,12 +365,12 @@ def emit_typed_stub_to_python_method(self, typebld, function_info):
365365
p = method_builder.DefineParameter(i + 1, ParameterAttributes_None, arg_names[i + instance_offset])
366366

367367
ilgen = method_builder.GetILGenerator()
368-
368+
369369
args_array = ilgen.DeclareLocal(Array[object])
370370
args_count = len(function.arg_types)
371371
ilgen.Emit(OpCodes.Ldc_I4, args_count)
372372
ilgen.Emit(OpCodes.Newarr, object)
373-
ilgen.Emit(OpCodes.Stloc, args_array)
373+
ilgen.Emit(OpCodes.Stloc, args_array)
374374
for i in range(args_count):
375375
arg_type = function.arg_types[i]
376376
if clr.GetClrType(arg_type).IsByRef:
@@ -380,7 +380,7 @@ def emit_typed_stub_to_python_method(self, typebld, function_info):
380380
ilgen.Emit(OpCodes.Ldarg, i + int(not function_info.is_static))
381381
ilgen.Emit(OpCodes.Box, arg_type)
382382
ilgen.Emit(OpCodes.Stelem_Ref)
383-
383+
384384
has_return_value = True
385385
if function_info.prop_name_if_prop_get:
386386
ilgen.Emit(OpCodes.Ldsfld, ClrClass.get_dynamic_operations_field())
@@ -401,7 +401,7 @@ def emit_typed_stub_to_python_method(self, typebld, function_info):
401401
# ilgen.Emit(OpCodes.Ldsfld, class_object)
402402
else:
403403
ilgen.Emit(OpCodes.Ldarg, 0)
404-
404+
405405
ilgen.Emit(OpCodes.Ldstr, function.__name__)
406406
ilgen.Emit(OpCodes.Ldloc, args_array)
407407
ilgen.Emit(OpCodes.Callvirt, invoke_member)
@@ -460,7 +460,7 @@ def emit_method(self, typebld, function_info):
460460
method_builder.SetCustomAttribute(cab)
461461

462462
return method_builder
463-
463+
464464
def map_pinvoke_methods(self, new_type):
465465
pythonType = clr.GetPythonType(new_type)
466466
for function_info in self.get_typed_methods():
@@ -469,20 +469,20 @@ def map_pinvoke_methods(self, new_type):
469469
# Overwrite the Python function with the pinvoke_method
470470
pinvoke_method = getattr(pythonType, function.__name__)
471471
setattr(self, function.__name__, pinvoke_method)
472-
472+
473473
def emit_python_type_field(self, typebld):
474474
return typebld.DefineField(
475475
"PythonType",
476476
PythonType,
477477
FieldAttributes.Public | FieldAttributes.Static)
478478

479479
def set_python_type_field(self, new_type):
480-
self.PythonType = new_type.GetField("PythonType")
480+
self.PythonType = new_type.GetField("PythonType")
481481
self.PythonType.SetValue(None, self)
482482

483483
def add_wrapper_ctors(self, baseType, typebld):
484484
python_type_field = self.emit_python_type_field(typebld)
485-
for ctor in baseType.GetConstructors():
485+
for ctor in baseType.GetConstructors():
486486
ctorparams = ctor.GetParameters()
487487

488488
# leave out the PythonType argument
@@ -500,19 +500,19 @@ def add_wrapper_ctors(self, baseType, typebld):
500500
ilgen.Emit(OpCodes.Ldarg, index + 1)
501501
ilgen.Emit(OpCodes.Call, ctor)
502502
ilgen.Emit(OpCodes.Ret)
503-
503+
504504
def emit_members(self, typebld):
505505
self.emit_fields(typebld)
506506
self.add_wrapper_ctors(self.baseType, typebld)
507507
super(ClrClass, self).emit_members(typebld)
508-
508+
509509
def map_members(self, new_type):
510510
self.map_fields(new_type)
511511
self.map_pinvoke_methods(new_type)
512512
self.set_python_type_field(new_type)
513513
super(ClrClass, self).map_members(new_type)
514514

515-
def __clrtype__(self):
515+
def __clrtype__(self):
516516
# CDerived below will use ClrClass as its metaclass, but the user may not expect CDerived
517517
# to be a typed .NET class in this case:
518518
#
@@ -522,9 +522,9 @@ def __clrtype__(self):
522522
if not "__metaclass__" in self.__dict__:
523523
return super(ClrClass, self).__clrtype__()
524524

525-
# Create a simple Python type first.
525+
# Create a simple Python type first.
526526
self.baseType = super(ClrType, self).__clrtype__()
527-
# We will now subtype it to create a customized class with the
527+
# We will now subtype it to create a customized class with the
528528
# CLR attributes as defined by the user
529529
typegen = Snippets.Shared.DefineType(self.get_clr_type_name(), self.baseType, True, False)
530530
typebld = typegen.TypeBuilder
@@ -537,7 +537,7 @@ def make_cab(attrib_type, *args, **kwds):
537537

538538
props = ([],[])
539539
fields = ([],[])
540-
540+
541541
for kwd in kwds:
542542
pi = clrtype.GetProperty(kwd)
543543
if pi is not None:
@@ -550,9 +550,9 @@ def make_cab(attrib_type, *args, **kwds):
550550
fields[1].append(kwds[kwd])
551551
else:
552552
raise TypeError("No %s Member found on %s" % (kwd, clrtype.Name))
553-
554-
return CustomAttributeBuilder(ci, args,
555-
tuple(props[0]), tuple(props[1]),
553+
554+
return CustomAttributeBuilder(ci, args,
555+
tuple(props[0]), tuple(props[1]),
556556
tuple(fields[0]), tuple(fields[1]))
557557

558558
def accepts(*args):
@@ -582,11 +582,11 @@ class CustomAttributeDecorator(object):
582582
Note that we cannot use an instance of System.Attribute to capture this information
583583
as it is not possible to go from an instance of System.Attribute to an instance
584584
of System.Reflection.Emit.CustomAttributeBuilder as the latter needs to know
585-
how to represent information in metadata to later *recreate* a similar instance of
585+
how to represent information in metadata to later *recreate* a similar instance of
586586
System.Attribute.
587-
587+
588588
Also note that once a CustomAttributeBuilder is created, it is not possible to
589-
query it. Hence, we need to store the arguments required to store the
589+
query it. Hence, we need to store the arguments required to store the
590590
CustomAttributeBuilder so that pseudo-custom-attributes can get to the information.
591591
"""
592592
def __init__(self, attrib_type, *args, **kwargs):
@@ -629,4 +629,3 @@ def propagate_attributes(old_function, new_function):
629629
new_function.CustomAttributeBuilders = old_function.CustomAttributeBuilders
630630
if hasattr(old_function, "CustomAttributeBuilders"):
631631
new_function.DllImportAttributeDecorator = old_function.DllImportAttributeDecorator
632-

0 commit comments

Comments
 (0)