Best Python code snippet using localstack_python
scaffold.py
Source:scaffold.py
...71 return [shape.member.name]72 if isinstance(shape, MapShape):73 return [shape.key.name, shape.value.name]74 return []75 def _print_structure_declaration(self, output, doc=True, quote_types=False):76 if self.is_exception:77 self._print_as_class(output, "ServiceException", doc)78 return79 if any(map(is_keyword, self.shape.members.keys())):80 self._print_as_typed_dict(output)81 return82 if self.is_request:83 base = "ServiceRequest"84 else:85 base = "TypedDict, total=False"86 self._print_as_class(output, base, doc, quote_types)87 def _print_as_class(self, output, base: str, doc=True, quote_types=False):88 output.write(f"class {self.shape.name}({base}):\n")89 q = '"' if quote_types else ""90 if doc:91 self.print_shape_doc(output, self.shape)92 if not self.shape.members:93 output.write(" pass\n")94 for k, v in self.shape.members.items():95 if k in self.shape.required_members:96 output.write(f" {k}: {q}{v.name}{q}\n")97 else:98 output.write(f" {k}: Optional[{q}{v.name}{q}]\n")99 def _print_as_typed_dict(self, output, doc=True, quote_types=False):100 name = self.shape.name101 q = '"' if quote_types else ""102 output.write('%s = TypedDict("%s", total=False, fields={\n' % (name, name))103 for k, v in self.shape.members.items():104 if k in self.shape.required_members:105 output.write(f' "{k}": {q}{v.name}{q},\n')106 else:107 output.write(f' "{k}": Optional[{q}{v.name}{q}],\n')108 output.write("})")109 def print_shape_doc(self, output, shape):110 html = shape.documentation111 import pypandoc112 doc = pypandoc.convert_text(html, "rst", format="html")113 rst = doc.strip()114 if rst:115 output.write(' """')116 output.write(f"{doc.strip()}\n")117 output.write(' """\n')118 def print_declaration(self, output, doc=True, quote_types=False):119 shape = self.shape120 q = '"' if quote_types else ""121 if isinstance(shape, StructureShape):122 self._print_structure_declaration(output, doc, quote_types)123 elif isinstance(shape, ListShape):124 output.write(f"{shape.name} = List[{q}{shape.member.name}{q}]")125 elif isinstance(shape, MapShape):126 output.write(f"{shape.name} = Dict[{q}{shape.key.name}{q}, {q}{shape.value.name}{q}]")127 elif isinstance(shape, StringShape):128 if shape.enum:129 output.write(f"class {shape.name}(str):\n")130 for value in shape.enum:131 name = to_valid_python_name(value)132 output.write(f' {name} = "{value}"\n')133 else:134 output.write(f"{shape.name} = str")135 elif shape.type_name == "string":136 output.write(f"{shape.name} = str")...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!