MCPcopy Create free account
hub / github.com/astral-sh/ruff / unparse_pattern

Method unparse_pattern

crates/ruff_python_codegen/src/generator.rs:769–861  ·  view source on GitHub ↗
(&mut self, ast: &Pattern)

Source from the content-addressed store, hash-verified

767 }
768
769 fn unparse_pattern(&mut self, ast: &Pattern) {
770 match ast {
771 Pattern::MatchValue(ast::PatternMatchValue {
772 value,
773 range: _,
774 node_index: _,
775 }) => {
776 self.unparse_expr(value, precedence::MAX);
777 }
778 Pattern::MatchSingleton(ast::PatternMatchSingleton {
779 value,
780 range: _,
781 node_index: _,
782 }) => {
783 self.unparse_singleton(*value);
784 }
785 Pattern::MatchSequence(ast::PatternMatchSequence {
786 patterns,
787 range: _,
788 node_index: _,
789 }) => {
790 self.p("[");
791 let mut first = true;
792 for pattern in patterns {
793 self.p_delim(&mut first, ", ");
794 self.unparse_pattern(pattern);
795 }
796 self.p("]");
797 }
798 Pattern::MatchMapping(ast::PatternMatchMapping {
799 keys,
800 patterns,
801 rest,
802 range: _,
803 node_index: _,
804 }) => {
805 self.p("{");
806 let mut first = true;
807 for (key, pattern) in keys.iter().zip(patterns) {
808 self.p_delim(&mut first, ", ");
809 self.unparse_expr(key, precedence::MAX);
810 self.p(": ");
811 self.unparse_pattern(pattern);
812 }
813 if let Some(rest) = rest {
814 self.p_delim(&mut first, ", ");
815 self.p("**");
816 self.p_id(rest);
817 }
818 self.p("}");
819 }
820 Pattern::MatchClass(_) => {}
821 Pattern::MatchStar(ast::PatternMatchStar {
822 name,
823 range: _,
824 node_index: _,
825 }) => {
826 self.p("*");

Callers 1

unparse_match_caseMethod · 0.80

Calls 6

unparse_singletonMethod · 0.80
pMethod · 0.80
p_delimMethod · 0.80
p_idMethod · 0.80
unparse_exprMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected