def validate_tz_from_dtype(dtype, tz):
if dtype is not None:<EOL><INDENT>if isinstance(dtype, str):<EOL><INDENT>try:<EOL><INDENT>dtype = DatetimeTZDtype.construct_from_string(dtype)<EOL><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>dtz = getattr(dtype, '<STR_LIT>', None)<EOL>if dtz is not None:<EOL><INDENT>if tz is not None and not timezones.tz_compare(tz, dtz):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>tz = dtz<EOL><DEDENT>if tz is not None and is_datetime64_dtype(dtype):<EOL><INDENT>if tz is not None and not timezones.tz_compare(tz, dtz):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>return tz<EOL>
If the given dtype is a DatetimeTZDtype, extract the implied
tzinfo object from it and check that it does not conflict with the given
tz.

Parameters
----------
dtype : dtype, str
tz : None, tzinfo

Returns
-------
tz : consensus tzinfo

Raises
------
ValueError : on tzinfo mismatch