### anomalous behaviour of bc.homogenize() with list comprehension

150

views

0

Consider bcs is a list of DirichletBC instances.

If I do

bcs_h = [bc.homogenize() for bc in bcs]

for bc in bcs_h:

print type(bc)

It gives <type 'NoneType'>

But if I do

bcs_h =[]

for bc in bcs:

bc.homogenize()

bcs_h.append(bc)

then each element of bcs_h seems to be <class 'dolfin.fem.bcs.DirichletBC'>

In both cases, bcs_h is obtained by bc.homogenize(), but why is it NoneType in first case ?

If I do

bcs_h = [bc.homogenize() for bc in bcs]

for bc in bcs_h:

print type(bc)

It gives <type 'NoneType'>

But if I do

bcs_h =[]

for bc in bcs:

bc.homogenize()

bcs_h.append(bc)

then each element of bcs_h seems to be <class 'dolfin.fem.bcs.DirichletBC'>

In both cases, bcs_h is obtained by bc.homogenize(), but why is it NoneType in first case ?

Community: FEniCS Project

### 1 Answer

2

Clearly, bc.homogenize() returns None.

So bc.homogenize() changes bc in-place but returns None ?

written
8 months ago by
Shriram S

Well, strictly speaking homogenize() is an instance method so "in-place" does not apply. Python functions without a "return" clause return "None" by default.

written
8 months ago by
pf4d

Please login to add an answer/comment or follow this question.