uranusjr commented on a change in pull request #20482:
URL: https://github.com/apache/airflow/pull/20482#discussion_r774780261
##########
File path: airflow/utils/timezone.py
##########
@@ -133,10 +138,10 @@ def make_aware(value: Optional[dt.datetime], timezone:
Optional["Timezone"] = No
value = value.replace(fold=1)
if hasattr(timezone, 'localize'):
# This method is available for pytz time zones.
- return timezone.localize(value)
+ return cast(Any, timezone).localize(value)
Review comment:
+1 to `getattr`. A less-known fact: For user-defined classes (i.e. not
something like `int` or `str`), `hasattr` is actually roughly equivalent to
```python
def hasattr(obj, name):
try:
getattr(obj, name)
except AttributeError:
return False
return True
```
So if you need to get the value at some point, `getattr` is always superior
to `hasattr`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]