This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Meta(type): | |
| def __new__(meta, name, bases, class_dict): | |
| for key, value in class_dict.items(): | |
| if isinstance(value, Field): | |
| value.name = key | |
| value.internal_name = '_' + key | |
| cls = type.__new__(meta, name, bases, class_dict) | |
| return cls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BetterSerializable(object): | |
| def __init__(self, *args): | |
| self.args = args | |
| def serialize(self): | |
| return json.dumps({ | |
| 'class': self.__class__.__name__, | |
| 'agrs': self.args, | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ValidatePolygon(type): | |
| def __new__(meta, name, bases, class_dict): | |
| if bases != (object,): | |
| if class_dict['sides'] < 3: | |
| raise ValueError | |
| return type.__new__(meta, name, bases, class_dict) | |
| class Ploygon(object, metaclass=ValidatePolygon): | |
| sides = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FixedResistance(Resistor): | |
| @property | |
| def ohms(self): | |
| return self._ohms | |
| @ohms.setter | |
| def ohms(self, ohms): | |
| if hasattr(self, '_ohms'): | |
| raise AttributeError("Невозможно установить атрибут") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import UserDict | |
| class distinctdict(UserDict): | |
| def __setitem__(self, key, value): | |
| if value in self.values(): | |
| if ((key in self and self[key] != value) or key not in self): | |
| raise DistinctError("This value already exists for different key") | |
| super().__setitem__(key, value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ToDictMixin(object): | |
| def to_dict(self): | |
| return self._traverse_dict(self.__dict__) | |
| def _traverse_dict(self, instance_dict): | |
| output = {} | |
| for key, value in instance_dict.items(): | |
| output[key] = self._traverse(key, value) | |
| return output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| class GenericInputData(object): | |
| def read(self): | |
| raise NotImplementedError | |
| @classmethod | |
| def generate_inputs(cls, config): | |
| raise NotImplementedError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace LoggingDemo.Commands | |
| { | |
| public interface ICommand | |
| { | |
| void Execute(); | |
| } | |
| public interface ICommandFactory | |
| { | |
| string CommandName { get; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "sync" | |
| "time" | |
| ) | |
| func merger(a chan int, b chan int) chan int { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "sync" | |
| "time" | |
| ) | |
| func joiner(inputs []chan string) chan string { |