Skip to content

Commit

Permalink
Activate pylint convention rules in ruff (streamlit#8874)
Browse files Browse the repository at this point in the history
## Describe your changes

This PR activates the pylint convention rules in ruff + updates ruff to
0.5.

## Testing Plan

- No logical changes -> no tests required

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
  • Loading branch information
lukasmasuch authored Jun 28, 2024
1 parent e099646 commit f4b5b81
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
22 changes: 12 additions & 10 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ select = [
"ISC", # Encourage correct string literal concatenation.
"LOG", # Checks for issues using the standard library logging module.
"NPY", # Linting rules for numpy
"PLC", # pycodestyle conventions
"PYI", # Linting rules for type annotations.
"Q", # Linting rules for quites
"RUF100", # Unused noqa directive
Expand All @@ -44,15 +45,16 @@ select = [
"W", # pycodestyle warnings
]
ignore = [
"B008", # Checks for function calls in default function arguments.
"B904", # Checks for raise statements in exception handlers that lack a from clause.
"E501", # Checks for lines that exceed the specified maximum character length.
"ISC001", # Checks for implicitly concatenated strings on a single line.
"NPY002", # Checks for the use of legacy np.random function calls.
"PYI036", # Checks for incorrect function signatures on __exit__ and __aexit__ methods.
"PYI041", # Checks for parameter annotations that contain redundant unions between builtin numeric types (e.g., int | float).
"PYI051", # Checks for redundant unions between a Literal and a builtin supertype of that Literal.
"UP031", # Checks for printf-style string formatting, and offers to replace it with str.format calls.
"B008", # Checks for function calls in default function arguments.
"B904", # Checks for raise statements in exception handlers that lack a from clause.
"E501", # Checks for lines that exceed the specified maximum character length.
"ISC001", # Checks for implicitly concatenated strings on a single line.
"NPY002", # Checks for the use of legacy np.random function calls.
"PYI036", # Checks for incorrect function signatures on __exit__ and __aexit__ methods.
"PYI041", # Checks for parameter annotations that contain redundant unions between builtin numeric types (e.g., int | float).
"PYI051", # Checks for redundant unions between a Literal and a builtin supertype of that Literal.
"UP031", # Checks for printf-style string formatting, and offers to replace it with str.format calls.
"PLC0208", # Checks for iterations over set literals.
]
# Do not lint files in tests, scripts, and vendor directory:
exclude = [
Expand All @@ -64,7 +66,7 @@ exclude = [

[lint.per-file-ignores]
"e2e_playwright/**" = ["T20", "B018"]
"lib/streamlit/__init__.py" = ["E402"]
"lib/streamlit/__init__.py" = ["E402", "PLC0414"]

[lint.flake8-tidy-imports]
# Disallow all relative imports.
Expand Down
2 changes: 1 addition & 1 deletion e2e_playwright/st_graphviz_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import graphviz as graphviz
import graphviz

import streamlit as st

Expand Down
2 changes: 1 addition & 1 deletion lib/dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pre-commit
# We fix ruff to a version to be in sync with the pre-commit hook:
ruff==0.4.8
ruff==0.5
mypy>=1.4, <1.7
mypy-protobuf>=3.2
# semver 3 renames VersionInfo so temporarily pin until we deal with it
Expand Down
2 changes: 1 addition & 1 deletion lib/streamlit/components/v1/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
# model the old behavior and not to break things.

from streamlit.components.v1.component_registry import (
declare_component as declare_component,
declare_component as declare_component, # noqa: PLC0414
)
from streamlit.components.v1.custom_component import * # noqa: F403
22 changes: 11 additions & 11 deletions lib/streamlit/testing/v1/element_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ def set_value(self, v: Any):
def _widget_state(self) -> WidgetState: ...


El = TypeVar("El", bound=Element, covariant=True)
El_co = TypeVar("El_co", bound=Element, covariant=True)


class ElementList(Generic[El]):
def __init__(self, els: Sequence[El]):
self._list: Sequence[El] = els
class ElementList(Generic[El_co]):
def __init__(self, els: Sequence[El_co]):
self._list: Sequence[El_co] = els

def __len__(self) -> int:
return len(self._list)
Expand All @@ -216,12 +216,12 @@ def len(self) -> int:
return len(self)

@overload
def __getitem__(self, idx: int) -> El: ...
def __getitem__(self, idx: int) -> El_co: ...

@overload
def __getitem__(self, idx: slice) -> ElementList[El]: ...
def __getitem__(self, idx: slice) -> ElementList[El_co]: ...

def __getitem__(self, idx: int | slice) -> El | ElementList[El]:
def __getitem__(self, idx: int | slice) -> El_co | ElementList[El_co]:
if isinstance(idx, slice):
return ElementList(self._list[idx])
else:
Expand All @@ -233,7 +233,7 @@ def __iter__(self):
def __repr__(self):
return util.repr_(self)

def __eq__(self, other: ElementList[El] | object) -> bool:
def __eq__(self, other: ElementList[El_co] | object) -> bool:
if isinstance(other, ElementList):
return self._list == other._list
else:
Expand All @@ -244,11 +244,11 @@ def values(self) -> Sequence[Any]:
return [e.value for e in self]


W = TypeVar("W", bound=Widget, covariant=True)
W_co = TypeVar("W_co", bound=Widget, covariant=True)


class WidgetList(ElementList[W], Generic[W]):
def __call__(self, key: str) -> W:
class WidgetList(ElementList[W_co], Generic[W_co]):
def __call__(self, key: str) -> W_co:
for e in self._list:
if e.key == key:
return e
Expand Down

0 comments on commit f4b5b81

Please sign in to comment.