text stringlengths 0 828 |
|---|
_todos.append(todo) |
if not _todos: |
self._show_no_todos(text_fix='No {} todos...'.format( |
STATUS_CODE.get(status, None))) |
else: |
for todo in _todos: |
self._show_todos(todo) |
else: |
for todo in self.todos: |
self._show_todos(todo) |
_show('', 50)" |
347,"def write(self, delete_if_empty=False): |
""""""flush todos to file |
:param delete_if_empty: delete if todo is empty |
"""""" |
with open(self.path, 'w') as f: |
if not self.todos: |
f.flush() |
else: |
for todo in _todo_to_file(self.todos): |
f.write(todo)" |
348,"def read_object_from_pickle(desired_type: Type[T], file_path: str, encoding: str, |
fix_imports: bool = True, errors: str = 'strict', *args, **kwargs) -> Any: |
"""""" |
Parses a pickle file. |
:param desired_type: |
:param file_path: |
:param encoding: |
:param fix_imports: |
:param errors: |
:param args: |
:param kwargs: |
:return: |
"""""" |
import pickle |
file_object = open(file_path, mode='rb') |
try: |
return pickle.load(file_object, fix_imports=fix_imports, encoding=encoding, errors=errors) |
finally: |
file_object.close()" |
349,"def should_display_warnings_for(to_type): |
"""""" Central method where we control whether warnings should be displayed """""" |
if not hasattr(to_type, '__module__'): |
return True |
elif to_type.__module__ in {'builtins'} or to_type.__module__.startswith('parsyfiles') \ |
or to_type.__name__ in {'DataFrame'}: |
return False |
elif issubclass(to_type, int) or issubclass(to_type, str) \ |
or issubclass(to_type, float) or issubclass(to_type, bool): |
return False |
else: |
return True" |
350,"def _is_valid_for_dict_to_object_conversion(strict_mode: bool, from_type: Type, to_type: Type) -> bool: |
"""""" |
Returns true if the provided types are valid for dict_to_object conversion |
Explicitly declare that we are not able to parse collections nor able to create an object from a dictionary if the |
object's constructor is non correctly PEP484-specified. |
None should be treated as a Joker here (but we know that never from_type and to_type will be None at the same time) |
:param strict_mode: |
:param from_type: |
:param to_type: |
:return: |
"""""" |
# cache previous results |
try: |
res, subclasses_hash = _cache_valid_for_dict_to_object[to_type][strict_mode] |
# Check if are any new subclasses are available |
if not strict_mode and to_type is not None and not is_any_type(to_type): |
if hash(tuple(get_all_subclasses(to_type))) != subclasses_hash: |
raise KeyError('fake error to recompute the cache entry') |
except KeyError: |
res = __is_valid_for_dict_to_object_conversion(strict_mode=strict_mode, from_type=from_type, to_type=to_type) |
# Store an entry in the cache containing the result and the hash of the subclasses list |
subclasses_hash = None |
if not strict_mode and to_type is not None and not is_any_type(to_type): |
subclasses_hash = hash(tuple(get_all_subclasses(to_type))) |
entry = (res, subclasses_hash) |
try: |
_cache_valid_for_dict_to_object[to_type][strict_mode] = entry |
except KeyError: |
_cache_valid_for_dict_to_object[to_type] = {strict_mode: entry} |
return res" |
351,"def __is_valid_for_dict_to_object_conversion(strict_mode: bool, from_type: Type, to_type: Type) -> bool: |
"""""" |
Returns true if the provided types are valid for dict_to_object conversion |
Explicitly declare that we are not able to parse collections nor able to create an object from a dictionary if the |
object's constructor is non correctly PEP484-specified. |
None should be treated as a Joker here (but we know that never from_type and to_type will be None at the same time) |
:param strict_mode: |
:param from_type: |
:param to_type: |
:return: |
"""""" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.