Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix lint errors; format docstrings with ruff
Browse files Browse the repository at this point in the history
sloria committed Mar 13, 2024
1 parent 34cb549 commit 6c9c5a5
Showing 4 changed files with 25 additions and 12 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -75,6 +75,9 @@ exclude = [
"src/textblob/_text.py",
]

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
18 changes: 14 additions & 4 deletions src/textblob/blob.py
Original file line number Diff line number Diff line change
@@ -486,8 +486,14 @@ def pos_tags(self):
Example:
::
[('At', 'IN'), ('eight', 'CD'), ("o'clock", 'JJ'), ('on', 'IN'),
('Thursday', 'NNP'), ('morning', 'NN')]
[
("At", "IN"),
("eight", "CD"),
("o'clock", "JJ"),
("on", "IN"),
("Thursday", "NNP"),
("morning", "NN"),
]
:rtype: list of tuples
"""
@@ -775,8 +781,12 @@ def __repr__(self):
self.classifier.__class__.__name__ + "()" if self.classifier else "None"
)
return (
f"Blobber(tokenizer={self.tokenizer.__class__.__name__}(), pos_tagger={self.pos_tagger.__class__.__name__}(), "
f"np_extractor={self.np_extractor.__class__.__name__}(), analyzer={self.analyzer.__class__.__name__}(), parser={self.parser.__class__.__name__}(), classifier={classifier_name})"
f"Blobber(tokenizer={self.tokenizer.__class__.__name__}(), "
f"pos_tagger={self.pos_tagger.__class__.__name__}(), "
f"np_extractor={self.np_extractor.__class__.__name__}(), "
f"analyzer={self.analyzer.__class__.__name__}(), "
f"parser={self.parser.__class__.__name__}(), "
f"classifier={classifier_name})"
)

__str__ = __repr__
12 changes: 7 additions & 5 deletions src/textblob/formats.py
Original file line number Diff line number Diff line change
@@ -5,18 +5,20 @@
from textblob import formats
class PipeDelimitedFormat(formats.DelimitedFormat):
delimiter = '|'
delimiter = "|"
formats.register('psv', PipeDelimitedFormat)
formats.register("psv", PipeDelimitedFormat)
Once a format has been registered, classifiers will be able to read data files with
that format. ::
from textblob.classifiers import NaiveBayesAnalyzer
with open('training_data.psv', 'r') as fp:
cl = NaiveBayesAnalyzer(fp, format='psv')
with open("training_data.psv", "r") as fp:
cl = NaiveBayesAnalyzer(fp, format="psv")
"""

import csv
@@ -106,7 +108,7 @@ class JSON(BaseFormat):
[
{"text": "Today is a good day.", "label": "pos"},
{"text": "I hate this car.", "label": "neg"}
{"text": "I hate this car.", "label": "neg"},
]
"""

4 changes: 1 addition & 3 deletions tests/test_classifiers.py
Original file line number Diff line number Diff line change
@@ -328,9 +328,7 @@ def test_accuracy(self):
def test_repr(self):
assert (
repr(self.classifier)
== "<PositiveNaiveBayesClassifier trained on {} labeled and {} unlabeled instances>".format( # noqa: E501
len(self.classifier.positive_set), len(self.classifier.unlabeled_set)
)
== f"<PositiveNaiveBayesClassifier trained on {len(self.classifier.positive_set)} labeled and {len(self.classifier.unlabeled_set)} unlabeled instances>" # noqa: E501
)


0 comments on commit 6c9c5a5

Please sign in to comment.