def class_(self,
            *,
            pre_str: str = '',
            name: str,
            extra_docs: List[str] = (),
            end: str) -> None:
     new_class = Class(pre_str=pre_str)
     self.pyi.classes.append(new_class)
     new_class.class_def = f'class {name}:'
     new_class.doc = self.extra_notes(end=end, first_line='')
     if extra_docs:
         new_class.doc += extra_docs
 def class_from_file(
     self,
     *,
     pre_str: str = '',
     old: str,
     super_class: Optional[str] = None,
     extra_docs: List[str] = (),
     post_doc: str = '',
     end: Optional[str] = None,
 ) -> None:
     for line in self.rst:
         if line.lstrip().startswith(old):
             url = self._input_base_url + old.strip()
             self.rst.push_url(url)
             break
     else:
         assert False, f'Did not find: `{old}`!'
     rst_file_name = old[old.find('.') + 1:]
     class_name = rst_file_name[:rst_file_name.find('.')]
     if super_class is not None:
         class_name = f'{class_name}({super_class})'
     for class_title_lines in self.rst:  # Consume class title lines.
         if class_title_lines and set(class_title_lines).issubset(
                 self._title_underline):
             break
     self.consume_blank_line()
     doc = []
     for doc_line in self.rst:
         if self.is_last(doc_line, end):
             break
         if doc_line and set(doc_line).issubset(self._header_underline):
             assert doc[-1].strip(
             ), f'Expected a non-blank line, got blank!'  # Remove header.
             del doc[-1]
             assert not doc[-1].strip(
             ), f'Expected a blank line, got `{doc[-1]}`!'
             del doc[-1]
             break
         doc.append(f'   {doc_line}')
     else:
         assert doc, 'Did not find any class documentation.'
     if extra_docs:
         new_line = '\n'  # Can't have `\n` in between `{}` in f-string.
         doc.append(f'\n   {new_line.join(extra_docs)}')
     new_class = Class(pre_str=pre_str)
     self.pyi.classes.append(new_class)
     new_class.class_def = f'class {class_name}:'
     new_class.doc = doc
     new_class.imports_vars.append(post_doc)
示例#3
0
文件: course.py 项目: ntd275/project3
    def init_classes(self):
        self.classes = []
        for i in range(self.n_classes):
            self.classes.append(Class(i, self.max_n_places, self.n_classes))


# c = Course(1, [1, 2, 3])
# print(c._id)
示例#4
0
文件: object.py 项目: gsterjov/Myelin
 def get_class (self):
     klass = _lib.myelin_object_get_class (self)
     return Class.from_pointer (klass)
示例#5
0
 def get_class (self, name):
     klass = _lib.myelin_namespace_get_class (self, name)
     return Class.from_pointer (klass)