Repository: quantopian/zipline
File: zipline/algorithm.py (Python)

Code before:

        if self.trading_environment is None:
            self.trading_environment = TradingEnvironment()

        # Update the TradingEnvironment with the provided asset metadata
        if 'equities_metadata' in kwargs or 'futures_metadata' in kwargs:
            warnings.warn(
                'passing metadata to TradingAlgorithm is deprecated; please'
                ' write this data into the asset db before passing it to the'
                ' trading environment',
                DeprecationWarning,
                stacklevel=1,
            )
            self.trading_environment.write_data(
                equities=kwargs.pop('equities_metadata', None),
                futures=kwargs.pop('futures_metadata', None),
            )

        # If a schedule has been provided, pop it. Otherwise, use NYSE.
        calendar = kwargs.pop(
            'trading_calendar',
            "NYSE"
        )

        if not calendar:
            self.trading_calendar = get_calendar("NYSE")
        else:
            self.trading_calendar = get_calendar(calendar)

        self.sim_params = kwargs.pop('sim_params', None)
        if self.sim_params is None:
            self.sim_params = create_simulation_parameters(
                start=kwargs.pop('start', None),
                end=kwargs.pop('end', None),
                trading_calendar=self.trading_calendar,
            )

        self.perf_tracker = None
        # Pull in the environment's new AssetFinder for quick reference
        self.asset_finder = self.trading_environment.asset_finder

        # Initialize Pipeline API data.
        self.init_engine(kwargs.pop('get_pipeline_loader', None))
        self._pipelines = {}

        # Create an already-expired cache so that we compute the first time
        # data is requested.
        self._pipeline_cache = CachedObject.expired()

        self.blotter = kwargs.pop('blotter', None)
        self.cancel_policy = kwargs.pop('cancel_policy', NeverCancel())

Review comment (suggestion):
I'm pretty sure that if I'm using `kwargs.pop()` above that I can remove the `if` statement and just assign `self.trading_calendar` to `get_calendar(calendar)`

Code after:
        self.trading_environment = kwargs.pop('env', None)

        if self.trading_environment is None:
            self.trading_environment = TradingEnvironment()

        # Update the TradingEnvironment with the provided asset metadata
        if 'equities_metadata' in kwargs or 'futures_metadata' in kwargs:
            warnings.warn(
                'passing metadata to TradingAlgorithm is deprecated; please'
                ' write this data into the asset db before passing it to the'
                ' trading environment',
                DeprecationWarning,
                stacklevel=1,
            )
            self.trading_environment.write_data(
                equities=kwargs.pop('equities_metadata', None),
                futures=kwargs.pop('futures_metadata', None),
            )

        # If a schedule has been provided, pop it. Otherwise, use NYSE.
        self.trading_calendar = kwargs.pop(
            'trading_calendar',
            get_calendar('NYSE')
        )

        self.sim_params = kwargs.pop('sim_params', None)
        if self.sim_params is None:
            self.sim_params = create_simulation_parameters(
                start=kwargs.pop('start', None),
                end=kwargs.pop('end', None),
                trading_calendar=self.trading_calendar,
            )

        self.perf_tracker = None
        # Pull in the environment's new AssetFinder for quick reference
        self.asset_finder = self.trading_environment.asset_finder

        # Initialize Pipeline API data.
        self.init_engine(kwargs.pop('get_pipeline_loader', None))
        self._pipelines = {}

        # Create an already-expired cache so that we compute the first time
        # data is requested.
        self._pipeline_cache = CachedObject.expired()

        self.blotter = kwargs.pop('blotter', None)
        self.cancel_policy = kwargs.pop('cancel_policy', NeverCancel())
        if not self.blotter:
            self.blotter = Blotter(
                data_frequency=self.data_frequency,
                # Default to NeverCancel in zipline