Hey,
Does anybody know what ‘Any’ is?
i can import it from fastai.vision and when i try
Any??
in jupyter notebook i get the following:
Signature: Any(*args, **kwds)
Type: _SpecialForm
String form: typing.Any
File: d:\program_files\lib\typing.py
Source:
class _SpecialForm(_Final, _Immutable, _root=True):
"""Internal indicator of special typing constructs.
See _doc instance attribute for specific docs.
"""
__slots__ = ('_name', '_doc')
def __new__(cls, *args, **kwds):
"""Constructor.
This only exists to give a better error message in case
someone tries to subclass a special typing object (not a good idea).
"""
if (len(args) == 3 and
isinstance(args[0], str) and
isinstance(args[1], tuple)):
# Close enough.
raise TypeError(f"Cannot subclass {cls!r}")
return super().__new__(cls)
def __init__(self, name, doc):
self._name = name
self._doc = doc
def __eq__(self, other):
if not isinstance(other, _SpecialForm):
return NotImplemented
return self._name == other._name
def __hash__(self):
return hash((self._name,))
def __repr__(self):
return 'typing.' + self._name
def __reduce__(self):
return self._name
def __call__(self, *args, **kwds):
raise TypeError(f"Cannot instantiate {self!r}")
def __instancecheck__(self, obj):
raise TypeError(f"{self} cannot be used with isinstance()")
def __subclasscheck__(self, cls):
raise TypeError(f"{self} cannot be used with issubclass()")
@_tp_cache
def __getitem__(self, parameters):
if self._name == 'ClassVar':
item = _type_check(parameters, 'ClassVar accepts only single type.')
return _GenericAlias(self, (item,))
if self._name == 'Union':
if parameters == ():
raise TypeError("Cannot take a Union of no types.")
if not isinstance(parameters, tuple):
parameters = (parameters,)
msg = "Union[arg, ...]: each arg must be a type."
parameters = tuple(_type_check(p, msg) for p in parameters)
parameters = _remove_dups_flatten(parameters)
if len(parameters) == 1:
return parameters[0]
return _GenericAlias(self, parameters)
if self._name == 'Optional':
arg = _type_check(parameters, "Optional[t] requires a single type.")
return Union[arg, type(None)]
raise TypeError(f"{self} is not subscriptable")
Thank you