Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding types to pyi to detect API misuse #675

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions polyglot_piranha.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
# limitations under the License.

from __future__ import annotations
from typing import List, Optional
from typing import List, Optional, Literal

# Languages that Piranha supports (see ./src/models/language.rs)
PiranhaLanguage = Literal["java", "kt", "kotlin", "go", "py", "swift", "ts", "tsx", "thrift", "strings", "scm", "scala", "rb"]


def execute_piranha(piranha_argument: PiranhaArguments) -> list[PiranhaOutputSummary]:
"""
Expand All @@ -32,7 +36,7 @@ class PiranhaArguments:

def __init__(
self,
language: str,
language: PiranhaLanguage,
paths_to_codebase: Optional[List[str]] = None,
include: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
Expand All @@ -57,7 +61,7 @@ class PiranhaArguments:

Parameters
------------
language: str
language: PiranhaLanguage
the target language
paths_to_codebase: List[str]
Paths to source code folder or file
Expand Down
1 change: 1 addition & 0 deletions src/models/default_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use super::{
pub const JAVA: &str = "java";
pub const JAVA_CS: &str = "java_cs";
pub const KOTLIN: &str = "kt";
pub const KOTLIN_ALIAS: &str = "kotlin";
pub const GO: &str = "go";
pub const PYTHON: &str = "py";
pub const SWIFT: &str = "swift";
Expand Down
6 changes: 3 additions & 3 deletions src/models/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::utilities::parse_toml;

use super::{
default_configs::{
default_language, GO, JAVA, JAVA_CS, KOTLIN, PYTHON, RUBY, SCALA, STRINGS, SWIFT, THRIFT, TSX,
TS_SCHEME, TYPESCRIPT,
default_language, GO, JAVA, JAVA_CS, KOTLIN, KOTLIN_ALIAS, PYTHON, RUBY, SCALA, STRINGS, SWIFT,
THRIFT, TSX, TS_SCHEME, TYPESCRIPT,
},
outgoing_edges::Edges,
rule::Rules,
Expand Down Expand Up @@ -172,7 +172,7 @@ impl std::str::FromStr for PiranhaLanguage {
comment_nodes: vec!["comment".to_string()],
})
}
KOTLIN => {
KOTLIN | KOTLIN_ALIAS => {
let rules: Rules = parse_toml(include_str!("../cleanup_rules/kt/rules.toml"));
let edges: Edges = parse_toml(include_str!("../cleanup_rules/kt/edges.toml"));
Ok(PiranhaLanguage {
Expand Down
Loading