You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "hussein-awala (via GitHub)" <gi...@apache.org> on 2024/04/11 22:09:45 UTC

[PR] Use default_factory instead of calling the method in dataclass [airflow]

hussein-awala opened a new pull request, #38948:
URL: https://github.com/apache/airflow/pull/38948

   The method `get_airflow_extras` is called each time we import the module, which we can avoid by defining the attribute as a filed and setting the method as a default factory.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use default_factory instead of calling the method in dataclass [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #38948:
URL: https://github.com/apache/airflow/pull/38948#issuecomment-2054149367

   With cache it's good.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use default_factory instead of calling the method in dataclass [airflow]

Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala commented on PR #38948:
URL: https://github.com/apache/airflow/pull/38948#issuecomment-2054123990

   > AFAIK it is exact the opposite, default values assigned exactly once, as well as module imports exactly once, if do not count manual reload through importlib or clear sys.modules
   >
   > The problem with callable on default arguments that if it becomes mutable it will have all side effects of mutable.
   >
   > In the current proposal this function will call each time when new object of this dataclass instantiated
   
   I agree with this, but running the method at import time is often (if not always) not recommended, I added a `lru_cache` as TP suggested. WDYT?


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use default_factory instead of calling the method in dataclass [airflow]

Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on PR #38948:
URL: https://github.com/apache/airflow/pull/38948#issuecomment-2050671774

   AFAIK it is exact the opposite, default values assigned exactly once, as well as module imports exactly once, if do not count manual reload through importlib or clear sys.modules 
   
   The problem with callable on default arguments that if it becomes mutable it will have all side effects of mutable.
   
   In the current proposal this function will call each time when new object of this dataclass instantiated


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use default_factory instead of calling the method in dataclass [airflow]

Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala merged PR #38948:
URL: https://github.com/apache/airflow/pull/38948


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org