def _infer_tz_from_endpoints(start, end, tz):
try:<EOL><INDENT>inferred_tz = timezones.infer_tzinfo(start, end)<EOL><DEDENT>except Exception:<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>inferred_tz = timezones.maybe_get_tz(inferred_tz)<EOL>tz = timezones.maybe_get_tz(tz)<EOL>if tz is not None and inferred_tz is not None:<EOL><INDENT>if not timezones.tz_compare(inferred_tz, tz):<EOL><INDENT>raise AssertionError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>elif inferred_tz is not None:<EOL><INDENT>tz = inferred_tz<EOL><DEDENT>return tz<EOL>
If a timezone is not explicitly given via `tz`, see if one can
be inferred from the `start` and `end` endpoints.  If more than one
of these inputs provides a timezone, require that they all agree.

Parameters
----------
start : Timestamp
end : Timestamp
tz : tzinfo or None

Returns
-------
tz : tzinfo or None

Raises
------
TypeError : if start and end timezones do not agree