codeant-ai-for-open-source[bot] commented on code in PR #36756: URL: https://github.com/apache/superset/pull/36756#discussion_r2633216321
########## scripts/extract_feature_flags.py: ########## @@ -0,0 +1,194 @@ +#!/usr/bin/env python3 +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" +Extract feature flag metadata from superset/config.py. + +This script parses the annotated feature flags in config.py and outputs +a JSON file that can be consumed by the documentation site to generate +dynamic feature flag tables. + +Usage: + python scripts/extract_feature_flags.py > docs/static/feature-flags.json + +Annotations supported: + @lifecycle: development | testing | stable | deprecated + @docs: URL to documentation + @category: runtime_config | path_to_deprecation | internal (for stable flags) +""" + +import json +import re +import sys +from pathlib import Path +from typing import TypedDict + + +class FeatureFlag(TypedDict, total=False): + name: str + default: bool + lifecycle: str + description: str + docs: str | None + category: str | None + + +def extract_feature_flags(config_path: Path) -> list[FeatureFlag]: + """ + Parse config.py and extract feature flag metadata from comments. + + Each flag should have a comment block above it with: + - Description (first line(s) before @annotations) + - @lifecycle: development | testing | stable | deprecated + - @docs: URL (optional) + - @category: runtime_config | path_to_deprecation | internal (optional) + """ + content = config_path.read_text() + + # Find the DEFAULT_FEATURE_FLAGS dict + match = re.search( + r"DEFAULT_FEATURE_FLAGS:\s*dict\[str,\s*bool\]\s*=\s*\{(.+?)\n\}", Review Comment: **Suggestion:** The regex used to locate `DEFAULT_FEATURE_FLAGS` is tightly coupled to the exact type annotation `dict[str, bool]`, so if the annotation is ever changed (e.g. to `Dict[str, bool]`, a different mapping type, or removed), the script will fail to find the block and exit with an error, breaking feature flag docs generation. Relaxing the pattern to treat the type annotation as optional makes the script resilient to harmless annotation changes. [logic error] **Severity Level:** Minor ⚠️ ```suggestion r"DEFAULT_FEATURE_FLAGS\s*(?::\s*dict\[str,\s*bool\])?\s*=\s*\{(.+?)\n\}", ``` <details> <summary><b>Why it matters? ⭐ </b></summary> The current regex requires the exact annotation " : dict[str, bool] " to be present. That's brittle — if the annotation is removed, capitalized (Dict), or changed slightly the search will fail and the script will exit with an error. Making the annotation optional in the pattern (as proposed) fixes a real fragility in the script and improves resilience of docs generation. The proposed change directly addresses the failure mode described and is a safe improvement. </details> <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** scripts/extract_feature_flags.py **Line:** 64:64 **Comment:** *Logic Error: The regex used to locate `DEFAULT_FEATURE_FLAGS` is tightly coupled to the exact type annotation `dict[str, bool]`, so if the annotation is ever changed (e.g. to `Dict[str, bool]`, a different mapping type, or removed), the script will fail to find the block and exit with an error, breaking feature flag docs generation. Relaxing the pattern to treat the type annotation as optional makes the script resilient to harmless annotation changes. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. ``` </details> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
