Skip to content

Commit 1af6bf4

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Replace hasattr with getattr in vision/fair/pytorch3d/pytorch3d/renderer/cameras.py
Summary: The pattern ``` X.Y if hasattr(X, "Y") else Z ``` can be replaced with ``` getattr(X, "Y", Z) ``` The [getattr](https://www.w3schools.com/python/ref_func_getattr.asp) function gives more succinct code than the [hasattr](https://www.w3schools.com/python/ref_func_hasattr.asp) function. Please use it when appropriate. **This diff is very low risk. Green tests indicate that you can safely Accept & Ship.** Reviewed By: bottler Differential Revision: D44886893 fbshipit-source-id: 86ba23e837217e1ebd64bf8e27d286257894839e
1 parent 355d633 commit 1af6bf4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: pytorch3d/renderer/cameras.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,14 @@ def in_ndc(self):
375375
raise NotImplementedError()
376376

377377
def get_znear(self):
378-
return self.znear if hasattr(self, "znear") else None
378+
return getattr(self, "znear", None)
379379

380380
def get_image_size(self):
381381
"""
382382
Returns the image size, if provided, expected in the form of (height, width)
383383
The image size is used for conversion of projected points to screen coordinates.
384384
"""
385-
return self.image_size if hasattr(self, "image_size") else None
385+
return getattr(self, "image_size", None)
386386

387387
def __getitem__(
388388
self, index: Union[int, List[int], torch.BoolTensor, torch.LongTensor]

0 commit comments

Comments
 (0)